#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

void main(){
	int n,m,k,p,q=0,z=0;

	cin>>n>>m>>k;

	int a[32];

	int arr[1001];

	for(int i = 0; i<=m; i++){
		cin>>p;
		arr[i] = p;
	}

	int  x = arr[m];
	for(long  i=sizeof(x)*8-1; i>=0; --i)
	{
		a[i] = (int)((x>>i)&1);
		//cout<<a[i]<<"("<<i<<")";
		q++;
	}

	for(int i = 0; i<=m+1; i++){
		q = 0;
		x = arr[i];
		for(long  i=sizeof(x)*8-1; i>=0; --i)
		{
			if((int)((x>>i)&1) != a[i]){
				q++;
			}
		}
		if(q<=k){
			z++;
		}
	}

	cout<<(z-1);
}


#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

void main(){
	long n,m,k,p,q=0,z=0;

	cin>>n>>m>>k;

	long a[50];

	long arr[1001];

	for(long i = 0; i<=m; i++){
		cin>>p;
		arr[i] = p;
	}

	long x = arr[m];
	for(long i=sizeof(x)*8-1; i>=0; --i)
	{
		a[i] = (long)((x>>i)&1);
		q++;
	}

	for(long i = 0; i<=m+1; i++){
		q = 0;
		x = arr[i];
		for(long i=sizeof(x)*8-1; i>=0; --i)
		{
			if((long)((x>>i)&1) != a[i]){
				q++;
			}
		}
		if(q<=k){
			z++;
		}
	}

	cout<<(z-1);
}


#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

void main(){
	int n,m,k,p,q=0,z=0;

	cin>>n>>m>>k;

	int a[32];

	int arr[1001];

	for(int i = 0; i<=m; i++){
		cin>>p;
		arr[i] = p;
	}

	int  x = arr[m];
	for(long  i=sizeof(x)*8-1; i>=0; --i)
	{
		a[i] = (int)((x>>i)&1);
		q++;
	}

	for(int i = 0; i<=m+1; i++){
		q = 0;
		x = arr[i];
		for(long  i=sizeof(x)*8-1; i>=0; --i)
		{
			if((int)((x>>i)&1) != a[i]){
				q++;
			}
		}
		if(q<=k){
			z++;
		}
	}

	cout<<(z-1);
}


#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

void main(){
	long n,m,k,p,q=0,z=0;

	cin>>n>>m>>k;

	long a[50];

	long arr[1001];

	for(long i = 0; i<=m; i++){
		cin>>p;
		arr[i] = p;
	}

	long x = arr[m];
	for(long i=sizeof(x)*8-1; i>=0; --i)
	{
		a[i] = (long)((x>>i)&1);
		q++;
	}

	for(long i = 0; i<=m; i++){
		q = 0;
		x = arr[i];
		for(long i=sizeof(x)*8-1; i>=0; --i)
		{
			if((long)((x>>i)&1) != a[i]){
				q++;
			}
		}
		if(q<=k){
			z++;
		}
	}

	cout<<(z-1);
}


#include <iostream>
using namespace std;
#define maxm 1002
int x[maxm];
int main()
{
    int n,m,k,ans=0,xr,t1=0;
    cin >> n >> m >> k;
    for (int i=1;i<=m+1;i++)
        cin >> x[i];
    for (int i=1;i<=m;i++)
    {
        xr=x[i]^x[m+1];
        while(xr>0)
        {
            if (xr%2==1)
                t1++;
            xr/=2;
        }
        if (t1<=k)
            ans++;
        t1=0;
    }
    cout << ans;
}


#include <iostream>
#include <cmath>

using namespace std;
const int maxn=100010
int x[maxm];
int main()
{
    int n,m,k

    int tedad=0,dastan,y=0;

    cin >> n >> m >> k;

    for (int i=1;i<=m+1;i++)
        cin >> x[i];
    for (int i=1;i<=m;i++)
    {
        dastan=x[i]^x[m+1];
        while(dastan>=1)
        {
            if (dastan%2==1)
                        y++;
                    dastan/=2;
        }
        if (y<=k){
                tedad++;
                }
                y=0;
 }
    cout << tedad ;
}


#include <iostream>
#include <cmath>

using namespace std;
const int maxn=100010
int x[maxn];
int main()
{
    int n,m,k ;

    int tedad=0,dastan,y=0;

    cin >> n >> m >> k;

    for (int i=1;i<=m+1;i++)
        cin >> x[i];
    for (int i=1;i<=m;i++)
    {
        dastan=x[i]^x[m+1];
        while(dastan>=1)
        {
            if (dastan%2==1)
                        y++;
                    dastan/=2;
        }
        if (y<=k){
                tedad++;
                }
                y=0;
 }
    cout << tedad ;
}


#include <iostream>
#include <cmath>

using namespace std;
const int maxn=100010
int x[maxm];
int main()
{
    int n,m,k ;

    int tedad=0,dastan,y=0;

    cin >> n >> m >> k;

    for (int i=1;i<=m+1;i++)
        cin >> x[i];
    for (int i=1;i<=m;i++)
    {
        dastan=x[i]^x[m+1];
        while(dastan>=1)
        {
            if (dastan%2==1)
                        y++;
                    dastan/=2;
        }
        if (y<=k){
                tedad++;
                }
                y=0;
 }
    cout << tedad ;
}


#include <iostream>
#include <cmath>

using namespace std;
const int maxxx=100010
int x[maxxx];
int main()
{
    int n,m,k,r ;

    int tedad=0,dastan,y=0;

    cin >> n >> m >> k;

    for (int i=1;i<=m+1;i++)
        cin >> x[i];
    for (int i=1;i<=m;i++)
    {
        dastan=x[i]^x[m+1];
        while(dastan>=1)
        {
            if (dastan%2==1)
                        y++;
                    dastan/=2;
        }
        if (y<=k){
                tedad++;
                }
                y=0;
 }
    cout << tedad ;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m,k;
	int ans=0;
	cin>>n>>m>>k;
	vector<int> mas(m);
	for(int i=0;i<m;i++)
	{
		cin>>mas[i];
	}
	int fedya;
	cin>>fedya;
	vector<int> bits(1,1);
	for(int i=1;i<n;i++)
	{
		bits.push_back(bits[i-1]*2);
	}
	for(int i=0;i<m;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
			if(((fedya)&(bits[j]))!=((mas[i])&(bits[j])))
				cnt++;
		if(cnt<=k)
			ans++;
	}
	cout<<ans;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m,k;
	int ans=0;
	cin>>n>>m>>k;
	vector<int> mas(m);
	for(int i=0;i<m;i++)
	{
		cin>>mas[i];
	}
	int fedya;
	cin>>fedya;
	vector<int> bits(1,1);
	for(int i=1;i<n;i++)
	{
		bits[i]=bits[i-1]*2;
	}
	for(int i=0;i<m;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
			if(((fedya)&(bits[j]))!=((mas[i])&(bits[j])))
				cnt++;
		if(cnt<=k)
			ans++;
	}
	cout<<ans;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m,k;
	int ans=0;
	cin>>n>>m>>k;
	vector<int> mas(m);
	for(int i=0;i<m;i++)
	{
		cin>>mas[m];
	}
	int fedya;
	cin>>fedya;
	vector<int> bits(1,1);
	for(int i=1;i<n;i++)
	{
		bits[i]=bits[i-1]*2;
	}
	for(int i=0;i<m;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
			if(((fedya)&(bits[j]))!=((mas[i])&(bits[j])))
				cnt++;
		if(cnt<=k)
			ans++;
	}
	cout<<ans;
	return 0;
}


int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{int n;
    int i,ans=0,k,myself;
    long long int player[10005],m;
    cin>>n>>m>>k;

    for(i=0;i<m;i++){
		cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(player[i]^myself)<=k)
        {ans++;

        }
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{int n;
    int i,ans=0,k,myself;
    long long int player[10005],m;
    cin>>n>>m>>k;

    for(i=0;i<m;i++){
        cout<<"loop  run"<<endl;
		cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(player[i]^myself)<=k)
        {ans++;

        }
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{int n;
    int i,ans=0,k,myself,m;
    long long int player[10005];
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(player[i]^myself)<=k)
        {ans++;

        }

    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{
    int n,i,ans=0,k,myself;
    long int player[1005],m;
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{
    int n,i,ans=0,k,myself;
    long long int player[10005],m;
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{
    int n,i,ans=0,k,m,myself;
    int player[1005];
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return(1+(n1&(n1-1)));
}
int main()
{
    int n,i,ans=0,k,m,myself;
    int player[10005];
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{
    int n,i,ans=0,k,m,myself;
    int player[10005];
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


#include <iostream>

using namespace std;

int main()

{
    int n,m,k,sol,solv=0,tr;

    cin>>n>>m>>k;

    int nn[m+1];

   for(int o=0;o<=m;o++)cin>>nn[o];

   int trr=nn[m];

   for(int o=0;o<m;o++){

        int trrr=nn[o];

        sol=0;

        for(int i=31;i>=0;i--){

            int p1=0;

            if(trrr&(1<<i)){p1++;}

            if(trr&(1<<i)){p1++;}

            if(p1==1)sol++;

        }

       if(sol<=k)solv++;

   }

    cout<<solv<<"\n";

    return 0;

}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{
    int n,i,ans=0,k,m,myself;
    long int player[10005];
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{int n;
    int i,ans=0,k,myself;
    long long int player[10005],m;
    cin>>n>>m>>k;

    for(i=0;i<m;i++){

		cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(player[i]^myself)<=k)
        {ans++;

        }
    }
    cout<<ans;
}


# include<iostream>
# include<stdio.h>
using namespace std;
int main()
{
    int n,i,ans=0,k,m,myself;
    int player[10005];
    cin>>n,m,k;
    for(i=0;i<m;i++){
        cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(__builtin_count(myself^player[i])<=k)
        ans++;
    }
    cout<<ans;
}


# include<iostream>
using namespace std;
int count1s(int n1)
{
    if(n1==0)
    return 0;
    else
    return 1+count1s(n1&(n1-1));
}
int main()
{int n;
    int i,ans=0,k,myself;
    long long int player[10005],m;
    cin>>n>>m>>k;

    for(i=0;i<m;i++){
 		cin>>player[i];
    }
    cin>>myself;
    for(i=0;i<m;i++)
    {
        if(count1s(player[i]^myself)<=k)
        {ans++;

        }
    }
    cout<<ans;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
using namespace std;

int countNumBits1 (int mask)
{
	int ret = 0;
	while(mask){
		if(mask&1) ret++;
		mask >>=1;
	}
	return ret;
}

int main()
{
int n,m,k, ME, n_F = 0;
	cin >> n >> m >> k;
	vector <int> vec(n,0);
	for (int i = 0; i < m; i++)
		cin>>vec[i];
	cin >> ME;
	for (int i = 0; i < m; i++){
		int ME_OTh = ME ^ vec[i];
		if(countNumBits1(ME_OTh) <= k) n_F++;
	}
	cout << n_F << endl;return 0;
}


typedef long long ll;
typedef unsigned long long ull;

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <bitset>
#include <string>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <valarray>
#include <sstream>
#include <fstream>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>
using namespace std;

#define all(v) v.begin(),v.end()
#define lop(i,n) for(int i=0; i<n; i++)
#define rlop(i,n) for(int i=n-1; i>=0; i--)
#define loop(i,start,n) for(int i=start; i<n; i++)
#define rloop(i,start,n) for(int i=n-1; i>=end; i--)

vector<char> v,vec(2);
int inc=0, tdis2=0,dis2=0,dis1=0, tot=0, succ=0;

void gen()
{
	if(v.size() == inc){
		//process permutaion
		tot++;
		tdis2=dis2;
		lop(i,inc) { if(v[i] == '+') tdis2++; else tdis2--; }
		if(tdis2 == dis1) succ++;
	}
	else{
		for (int i = 0; i < 2; i++) {
			v.push_back(vec[i]);
			gen();
			v.pop_back();
		}
	}
}

int main()
{
//476B
	vec[0]='+'; vec[1]='-';
	string s1,s2, temp="";
	int size=0;
	cin>>s1>>s2;
	size=s1.size();
	lop(i,size) { if(s1[i] == '+') dis1++; else dis1--; }
	lop(i,size) { if(s2[i] == '+') dis2++; else if(s2[i] == '-') dis2--; else temp+=s2[i]; }
	inc=temp.size();
	gen();
	//cout << succ << endl << tot << endl;
	printf("%0.12f\n", float(succ)/tot);

return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
using namespace std;

int countNumBits1 (int mask)
{
	int ret = 0;
	while(mask){
		if(mask&1) ret++;
		mask >>=1;
	}
	return ret;
}

int main()
{
int n,m,k, ME, n_F = 0;
	cin >> n >> m >> k;
	vector <int> vec(m,0);
	for (int i = 0; i < m; i++)
		cin>>vec[i];
	cin >> ME;
	for (int i = 0; i < m; i++){
		int ME_OTh = ME ^ vec[i];
		if(countNumBits1(ME_OTh) <= k) n_F++;
	}
	cout << n_F << endl;return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <map>

int n,m,k,i,j,s,players[1000],p,x,z[22],pz[22];

void sol(){
    s=0;
    for(i=0;i<m;i++)scanf("%d",&players[i]);
    scanf("%d",&p);
    for(j=0;j<=21;j++)pz[j]=((p&(1<<j))>>j);
    for(i=0;i<m;i++){
        x=0;
        for(j=0;j<=21;j++)z[j]=0;
        for(j=0;j<=21;j++)z[j]=((players[i]&(1<<j))>>j);
        for(j=0;j<=21;j++)if(z[j]!=pz[j])x++;
        if(x<=k)s++;
//      for(j=0;j<=21;j++)printf("%d",z[j]);
//      printf("\n");
    }
//  for(j=0;j<=21;j++)printf("%d",pz[j]);
//  printf("\n");
    printf("%d ",s);
}

int main(){
    #pragma comment(linker, "/STACK:1073741824")
    #ifndef ONLINE_JUDGE
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    while(scanf("%d%d%d",&n,&m,&k)!=EOF)sol();
}


n,ak,bk=map(int,input().split())
k=ak+bk
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*n
for i in range(n):
    c[i]=abs(a[i]-b[i])
c.sort()
x=0
print(c)
coo=0
for i in range(k):
    c.sort()
    if c[n-1]==0:
        coo+=1
    c[n-1]=max(0,c[n-1]-1)
count=0
for i in range(n):
    count+=c[i]**2
print(count+coo%2)


n,ak,bk=map(int,input().split())
k=ak+bk
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*n
for i in range(n):
    c[i]=abs(a[i]-b[i])
c.sort()
x=0
coo=0
for i in range(k):
    c.sort()
    if c[n-1]==0:
        coo+=1
    c[n-1]=max(0,c[n-1]-1)
count=0
for i in range(n):
    count+=c[i]**2
print(count+coo%2)


n,ak,bk=map(int,input().split())
k=ak+bk
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*n
for i in range(n):
    c[i]=-abs(a[i]-b[i])
c.sort()
x=0
coo=0
for i in range(n):
    c[i]=-c[i]
for i in range(k):
    if x<n-1:
        while c[x]<=c[x+1]:
            if x+1<n-1:
                x+=1
            else:
                break
    if c[x]==0:
        coo+=1
    c[x]=max(0,c[x]-1)
    if x!=0:
        x-=1
count=0
for i in range(n):
    count+=c[i]**2
print(count+coo%2)


f=lambda: map(int,input().split())
n,k1,k2=f()
a,b=list(f()),list(f())
c=[]
k=k1+k2
for i in range(n):
    c.append(abs(a[i]-b[i]))
for i in range(k):
    c.sort()
    c[-1]=abs(c[-1]-1)
print( sum(x*x for x in c) )


n,x,y=(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0;ans=0
c=[]
k=x+y
import math
for i in range(n):
    c.append(abs(a[i]-b[i]))
    sum+=abs(a[i]-b[i])
c.sort(reverse=True)
#print(c)
if sum<=k:
    sum=(sum+x+y)%2
    print(sum)
else:
    for i in range(n-1):
        if c[i]-k<=c[i-1]:
            k-=(c[i]-c[i-1])
            c[i]=c[i-1]
        else:
            c[i]=c[i]-k
            k=0
            break
        if k==0:
            break
    #print(k,c)
    if k!=0:
        for i in range(n):
            if i<(k%n):
                c[i]-=(k//n + 1)
            else:
                c[i]-=(k//n)
    for i in range(n):
        #print(c[i])
        ans+=c[i]**2
    print(ans)


n,x,y=(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0
import math
for i in range(n):
    sum+=abs(a[i]-b[i])
if sum<=x+y:
    sum=(sum+x+y)%2
else:
    sum-=(x+y)
#print(sum)
if sum%n==0:
    print(sum**2 //n)
else:
    ans=((sum//n)**2)*(n-sum%n) + ((sum//n + 1)**2)*(sum%n)
    print(ans)


n,x,y=(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0
import math
for i in range(n):
    sum+=abs(a[i]-b[i])
sum=abs(sum-x-y)
#print(sum)
if sum%n==0:
    print(sum**2 //n)
else:
    ans=((sum//n)**2)*(n-sum%n) + ((sum//n + 1)**2)*(sum%n)
    print(ans)


n,x,y=(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0;ans=0
c=[]
k=x+y
import math
for i in range(n):
    c.append(abs(a[i]-b[i]))
    sum+=abs(a[i]-b[i])
c.sort(reverse=True)
#print(c)
if sum<=k:
    sum=(sum+x+y)%2
    #print(sum)
else:
    for i in range(n-1):
        if c[i]-k<=c[i-1]:
            k-=(c[i]-c[i-1])
            c[i]=c[i-1]
        else:
            c[i]=c[i]-k
            k=0
            break
        if k==0:
            break
    #print(k,c)
    if k!=0:
        for i in range(n):
            if i<(k%n):
                c[i]-=(k//n + 1)
            else:
                c[i]-=(k//n)
    for i in range(n):
        #print(c[i])
        ans+=c[i]**2
    print(ans)


import sys
n,k1,k2=map(int,input().split())
a=[int(i) for i in sys.stdin.readline().split()]
b=[int(i) for i in sys.stdin.readline().split()]
for i in range(n):
    a[i]=abs(a[i]-b[i])
for i in range(k1+k2):
    c=a.index(max(a))
    a[c]=abs(a[c]-1)
su=0
for i in a:
    su+=(i*i)
print(su)


n,x,y=(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum=0;ans=0
c=[]
k=x+y
import math
for i in range(n):
    c.append(a[i]-b[i])
    sum+=abs(a[i]-b[i])
c.sort(reverse=True)
if sum<=k:
    sum=(sum+x+y)%2
    print(sum)
else:
    for i in range(n-1):
        if c[i]-k<=c[i-1]:
            k-=(c[i]-c[i-1])
            c[i]=c[i-1]
        else:
            k=0
            c[i]=c[i]-k
            break
        if k==0:
            break
    if k!=0:
        for i in range(n):
            if i<(k%n):
                c[i]-=(k//n + 1)
            else:
                c[i]-=(k//n)
    for i in range(n):
        ans+=c[i]**2
    print(ans)


import heapq

def read():
    return [int(v) for v in input().split()]

def main():
    n, k1, k2 = read()
    k = k1 + k2
    a = read()
    b = read()
    c = [-abs(a - b) for (a, b) in zip(a, b)]
    heapq.heapify(c)
    while k:
        top = heapq.heappop(c)
        if top < 0:
            top += 1
            heapq.heappush(c, top)
        else:
            break
        k -= 1
    if k > 0:
        print(k%2)
        return
    print(sum(a*a for a in c))

if __name__ == '__main__':
    main()


n,k1,k2=map(int,input().split())
l=[]
k=k1+k2
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
	l.append(abs(a[i]-b[i]))
ans=0
for i in range(k):
	l.sort()
	if l[-1]>0:
		l[-1]-=1
	else:
		l[-1]+=1
for i in l:
	ans+=(i)**2
print(ans)


n,m,k = [int(i) for i in input().split()]
k=k+m
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [abs(a[i]-b[i]) for i in range(n)]
while k != 0:
	c.sort()
	c[-1] = abs(c[-1]-1)
	k-=1
t = 0
for i in range(n):
	t+=c[i]*c[i]
print(t)


def decrease_max(C, D):
    mx = (-1, -1)
    for i, e in enumerate(abs(c - d) for c, d in zip(C, D)):
        if e > mx[1]:
            mx = (i, e)
    i = mx[0]
    if C[i] > D[i]:
        C[i] -= 1
    else:
        C[i] += 1

def solution(k1, k2, A, B):
    for _ in range(k1):
        decrease_max(A, B)
    for _ in range(k2):
        decrease_max(B, A)
    return sum((a - b)**2 for a, b in zip(A, B))

n, k1, k2 = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(solution(k1, k2, A, B), end="")


import math
n,k1,k2= list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
d=[]
for i in range(len(a)):
    d.append(int(math.fabs(a[i]-b[i])))
k=k1+k2
for i in range(k):
    m=max(d)
    num=d.index(m)
    if m!=0:
        d[num]-=1
    else:
        d[num]+=1
s=0
for i in d:
    s+=i**2
print(s)


n, k, l = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

d = [abs(x - y) for x, y in zip(a, b)]

moves = k + l

d.sort()
d.reverse()

while moves > 0:
    if d[0] == 0:
        print(moves%2)
        break

    d[0] -= 1

    c = 0

    while c < n - 1 and d[c] < d[c + 1]:
        d[c], d[c + 1] = d[c + 1], d[c]
        c += 1

    moves -= 1
else:
    print(sum([x**2 for x in d]))


n,k1,k2 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = sorted([abs(a[i] - b[i]) for i in range(n)])[::-1]
k = k1+k2
cur = 0
for i in range(k):
    if c[0] == 0:break
    cur+=1
    c[0]-=1
    j=0
    while j+1 < n and c[j] < c[j+1]:
        c[j],c[j+1] = c[j+1],c[j]
        j+=1
k-=cur
if k > 0:
    print(k%2)
else:
    ans = 0
    for i in c:
        ans += i**2
    print(ans)


n,k1,k2 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = sorted([abs(a[i] - b[i]) for i in range(n)])[::-1]
k = k1+k2
cur = 0
for i in range(k):
    if c[0] == 0:break
    cur+=1
    c[0]-=1
    j=0
    while j+1 < n and c[j] < c[j+1]:
        c[j],c[j+1] = c[j+1],c[j]
        j+=1
k-=cur
d = k//n
for i in range(n):
      c[i]+=d
      k-=d
for i in range(k):
    c[i]+=1
ans = 0
for i in c:
    ans += i**2
print(ans)


n,k1,k2 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = sorted([abs(a[i] - b[i]) for i in range(n)])[::-1]
k = k1+k2
cur = 0
for i in range(k):
    if c[0] == 0:break
    cur+=1
    c[0]-=1
    j=0
    while j+1 < n and c[j] < c[j+1]:
        c[j],c[j+1] = c[j+1],c[j]
        j+=1
if cur == k:
    ans = 0
    for i in c:
        ans += i**2
    print(ans)
else:
    k-=cur
    print((k//n)**2+k%n)


from math import *
n,k1,k2=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=0
d=[]
k=k1+k2
for i in range(n):
    d.append((a[i]-b[i])*(a[i]-b[i]))
m=sum(d)
while((k)):
    k-=1
    ma=d.index(max(d))
    #m=abs(m-abs(a[ma]-b[ma])*abs(a[ma]-b[ma])+(abs(a[ma]-b[ma])-1)*(abs(a[ma]-b[ma])-1))
    d[ma]= (sqrt(d[ma])-1)*(sqrt(d[ma])-1)
print(int(sum(d)))


import heapq
n,k1,k2 = map(int,input().split())
a=list(map(int,input().split()))[:n]
b=list(map(int,input().split()))[:n]
total=k1+k2
arr=[]
for i in range(n):
    arr.append((-1)*abs(a[i]-b[i]))
heapq.heapify(arr)
while(total>0):
    item=(-1)*(heapq.heappop(arr))
    heapq.heappush(arr,(-1)*abs(item-1))
    total-=1
ans=0
for i in range(len(arr)):
    ans+=(arr[i])**2
print(ans)


p= lambda: map(int, input().split())
n,k,l=p();a=[abs(x-y) for x,y in zip(list(p()),list(p()))]
for _ in range(k+l):
    d=a.index(max(a));a[d]=abs(a[d]-1)
print(sum(i*i for i in a ))


from sys import stdin,stdout
from itertools import*
inp=lambda :(int(i) for i in  stdin.readline().split())
n,k1,k2=inp()
a=list(inp())
b=list(inp())
for i in range(n):
    a[i]=abs(a[i]-b[i])
for i in range(k1+k2):
    c=a.index(max(a))
    a[c]=abs(a[c]-1)
su=0
for i in a:
    su+=(i*i)
print(su)


inp= lambda: map(int, input().split())
n,k1,k2=inp()
a=[abs(x-y) for x,y in zip(list(inp()),list(inp()))]
for i in range(k1+k2):
    id=a.index(max(a))
    a[id]=abs(a[id]-1)
print(sum(i**2 for i in a ))


from sys import stdin,stdout
from itertools import*
inp=lambda :(int(i) for i in  stdin.readline().split())
n,k1,k2=inp()
a=[abs(x-y) for x,y in zip(list(inp()),list(inp()))]
for i in range(k1+k2):
    id=a.index(max(a))
    a[id]=abs(a[id]-1)
print(sum(i**2 for i in a ))


import sys
n,k1,k2=map(int,input().split())
a=[int(i) for i in sys.stdin.readline().split()]
b=[int(i) for i in sys.stdin.readline().split()]
for i in range(n):
    a[i]=abs(a[i]-b[i])
for i in range(k1+k2):
    c=a.index(max(a))
    a[c]=abs(a[c]-1)
su=0
for i in a:
    su+=(i*i)
print(su


from sys import stdin,stdout
from itertools import*
inp=lambda :(int(i) for i in  stdin.readline().split())
n,k1,k2=inp()
a=[abs(x-y) for x,y in zip(list(inp()),list(inp()))]
for i in range(k1+k2):
    id=a.index(max(a))
    a[id]=abs(a[id]-1)
stdout.write(str(sum(i**2 for i in a )))


R=lambda:map(int,input().split())
n,k,l=R()
k+=l
a=sorted((abs(x-y)for x,y in zip(R(),R())),reverse=True)
s=-k
i=0
for x,y in zip(a,a[1:]+[0]):
 s+=x
 if s-i*y>=0:
  l,m=s//i,s%i;print(l*l*(i-m)+(l+1)**2*m+sum(a[j]**2for j in range(i,n)));break
else:print((k-s)&1)


R=lambda:map(int,input().split())
n,k,l=R()
a=[abs(x-y)for x,y in zip(R(),R())]
for _ in[0]*(k+l):
 a.sort();a[-1]=abs(a[-1]-1)
print(sum(i*i for i in a))


R=lambda:map(int,input().split())
n,k,l=R()
k+=l
a=sorted((abs(x-y)for x,y in zip(R(),R())),reverse=True)
s=-k
i=0
for x,y in zip(a,a[1:]+[0]):
 i+=1;s+=x
 if s-i*y>=0:
  l,m=s//i,s%i;print(l*l*(i-m)+(l+1)**2*m+sum(a[j]**2for j in range(i,n)));break
else:print((k-s)&1)


R=lambda:map(int,input().split())
n,k,l=R()
a=[abs(x-y)for x,y in zip(R(),R())]
for _ in range(k+l):
 a.sort();a[-1]=abs(a[-1]-1)
print(sum(i*i for i in a))


R=lambda:map(int,input().split())
n,k,l=R()
a=[abs(x-y)for x,y in zip(R(),R())]
for _ in k+l:
 a.sort();a[-1]=abs(a[-1]-1)
print(i*i for i in a)


R=lambda:map(int,input().split())
n,k,l=R()
a=[abs(x-y)for x,y in zip(R(),R())]
for _ in k+l:
 a.sort();a[-1]=abs(a[-1]-1)
print(sum(i*i for i in a))


n,k1,k2 = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
for i in range(n):
    c.append(abs(a[i]-b[i]))
k = k1+k2
c.sort(reverse=True)
while(k!=0):
    if(c[0]==0):
        break
    c[0]-=1
    k-=1
    c.sort(reverse=True)
if(k!=0):
    if(k%2):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for i in c:
        ans+=i
print(ans)


n,k1,k2 = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
for i in range(n):
    c.append(abs(a[i]-b[i]))
k = k1+k2
c.sort(reverse=True)
while(k!=0):
    if(c[0]==0):
        break
    c[0]-=1
    k-=1
    c.sort(reverse=True)
if(k!=0):
    if(k%2):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for i in c:
        ans+=i**2
print(ans)


firstLine = input().strip().split(" ")
n = int(firstLine[0])
k1 = int(firstLine[1])
k2 = int(firstLine[2])

A = list(map(int,input().strip().split(" ")))
B = list(map(int,input().strip().split(" ")))

def findErrorInRankingTable():
    error = 0
    for item in rankingTable:
        error += (item[3])**2
    return error

"""Apply the addition or subtraction to the largest difference so that it minimizes error."""

"""Rank: 0 1 2 3
         A
         B
         D
"""
rankingTable = []
for i in range(n):
    difference = A[i]-B[i]
    rankingTable.append([i,A[i],B[i],difference**2])

#Sort the rankings by difference.
rankingTable.sort(key = lambda item: item[3])

#print(rankingTable)
#apply the k1 operations.
for i in range(k1):
    #Move the a value closer to the b value.
    if rankingTable[n-1][1] < rankingTable[n-1][2]:
        rankingTable[n-1][1] += 1
    else:
        rankingTable[n-1][1] -= 1
    #Recalculate difference.
    rankingTable[n-1][3] = (rankingTable[n-1][1] - rankingTable[n-1][2])**2
    #print(rankingTable)
    #Percolate new largest difference up if needed.
    rankingTable.sort(key = lambda item: item[3])

#apply the k2 operations.
for i in range(k2):
    #Move the a value closer to the b value.
    if rankingTable[n-1][2] < rankingTable[n-1][1]:
        rankingTable[n-1][2] += 1
    else:
        rankingTable[n-1][2] -= 1
    #Recalculate difference.
    rankingTable[n-1][3] = (rankingTable[n-1][1] - rankingTable[n-1][2])**2
    #print(rankingTable)
    #Percolate new largest difference up if needed.
    rankingTable.sort(key = lambda item: item[3])

#print(rankingTable)
print(findErrorInRankingTable())


firstLine = list(input().strip())
numA = firstLine.count('a')
numB = firstLine.count('b')
numC = firstLine.count('c')

startB = False
startC = False
for letter in firstLine:
    if startB == True and letter == 'a':
        print("NO")
        exit()
    if startC == True and letter == 'a':
        print("NO")
        exit()
    if startC == True and letter == 'b':
        print("NO")
        exit()
    if startB == False and letter == 'b':
        startB = True
    if startC == False and letter == 'c':
        startC = True

if (numC != numA and numC != numB and numC != numA+numB):
    print("NO")
    exit()
else:
    print("YES")


firstLine = input().strip().split(" ")
n = int(firstLine[0])
k1 = int(firstLine[1])
k2 = int(firstLine[2])

A = list(map(int,input().strip().split(" ")))
B = list(map(int,input().strip().split(" ")))

def findErrorInRankingTable():
    error = 0
    for item in rankingTable:
        error += item[3]
    return error

"""Apply the addition or subtraction to the largest difference so that it minimizes error."""

"""Rank: 0 1 2 3
         A
         B
         D
"""
rankingTable = []
for i in range(n):
    difference = A[i]-B[i]
    rankingTable.append([i,A[i],B[i],difference**2])

#Sort the rankings by difference.
rankingTable.sort(key = lambda item: item[3])

#print(rankingTable)
#apply the k1 operations.
for i in range(k1):
    #Move the a value closer to the b value.
    if rankingTable[n-1][1] < rankingTable[n-1][2]:
        rankingTable[n-1][1] += 1
    else:
        rankingTable[n-1][1] -= 1
    #Recalculate difference.
    rankingTable[n-1][3] = (rankingTable[n-1][1] - rankingTable[n-1][2])**2
    #print(rankingTable)
    #Percolate new largest difference up if needed.
    rankingTable.sort(key = lambda item: item[3])

#apply the k2 operations.
for i in range(k2):
    #Move the a value closer to the b value.
    if rankingTable[n-1][2] < rankingTable[n-1][1]:
        rankingTable[n-1][2] += 1
    else:
        rankingTable[n-1][2] -= 1
    #Recalculate difference.
    rankingTable[n-1][3] = (rankingTable[n-1][1] - rankingTable[n-1][2])**2
    #print(rankingTable)
    #Percolate new largest difference up if needed.
    rankingTable.sort(key = lambda item: item[3])

#print(rankingTable)
print(findErrorInRankingTable())


s = [int(x) for x in str.split(input())]
n, k1, k2 = s
a = [int(x) for x in str.split(input())]
b = [int(x) for x in str.split(input())]

dbst = [abs(a[0] - b[0])]
for i in range(1, n):
    dbst.append(abs(a[i] - b[i]))

dbst.sort()

su = 0

for i in range(k1 + k2, 0, -1):
    if dbst[-1] == 0:
        su += i % 2
        break
    dbst[-1] -= 1
    dbst.sort()

for i in range(n):
    su += dbst[i] * dbst[i]

print(su)


s = [int(x) for x in str.split(input())]
n, k1, k2 = s
a = [int(x) for x in str.split(input())]
b = [int(x) for x in str.split(input())]

dbst = [abs(a[0] - b[0])]
for i in range(1, n):
    dbst.append(abs(a[i] - b[i]))

dbst.sort()

su = 0

if len(dbst) == 1:
    if dbst[0] > k1 + k2:
        print(dbst[0] - (k1 + k2))
    else:
        print((dbst[0] + k1 + k2) % 2)
else:
    for i in range(k1 + k2, 0, -1):
        if dbst[-1] == 0:
            su += i % 2
            break
        dbst[-1] -= 1
        if dbst[-1] < dbst[-2]:
            dbst.sort()

    for i in range(n):
        su += dbst[i] * dbst[i]

    print(su)


s = [int(x) for x in str.split(input())]
n, k1, k2 = s
a = [int(x) for x in str.split(input())]
b = [int(x) for x in str.split(input())]

dbst = [abs(a[0] - b[0])]
for i in range(1, n):
    dbst.append(abs(a[i] - b[i]))

dbst.sort()

#print(dbst)

su = 0

for i in range(k1 + k2, 0, -1):
    if dbst[-1] == 0:
        su += i % 2
        break
    dbst[-1] -= 1
    if dbst[-1] < dbst[-2]:
        dbst.sort()

for i in range(n):
    su += dbst[i] * dbst[i]

print(su)


s = [int(x) for x in str.split(input())]
n, k1, k2 = s
a = [int(x) for x in str.split(input())]
b = [int(x) for x in str.split(input())]

dbst = [abs(a[0] - b[0])]
for i in range(1, n):
    dbst.append(abs(a[i] - b[i]))

dbst.sort()

su = 0

for i in range(k1 + k2, 0, -1):
    if dbst[-1] == 0:
        su += i % 2
        break
        dbst[-1] -= 1
    if len(dbst) > 1 and dbst[-1] < dbst[-2]:
        dbst.sort()

for i in range(n):
    su += dbst[i] * dbst[i]

print(su)


inp= lambda: map(int, input().split())
n,k1,k2=inp()
a=[abs(x-y) for x,y in zip(list(inp()),list(inp()))]
for i in range(k1+k2):
    id=a.index(max(a))
    a[id]=abs(a[id]-1)
print(sum(i**2 for i in a ))


n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

e = []

for ai, bi in zip(a, b):
	e.append(pow(ai - bi, 2))

for i in range(k1):
	 pos = e.index(max(e))
	 if a[pos] <= b[pos]:
	 	a[pos] += 1
	 else:
	 	a[pos] -= 1
	 e[pos] = (pow(a[pos] - b[pos], 2))

for i in range(k2):
	 pos = e.index(max(e))
	 if b[pos] <= a[pos]:
	 	b[pos] += 1
	 else:
	 	b[pos] -= 1
	 e[pos] = (pow(a[pos] - b[pos], 2))

print(sum(e))


def solve(k1, k2, a, b):
    e = sum([abs(i - j) for i, j in zip(a, b)])
    diff = e - (k1 + k2)
    return diff if diff > 0 else abs(diff) % 2

if __name__ == '__main__':
    _, k1, k2 = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    print(solve(k1, k2, a, b))


def solve(k1, k2, a, b):
    d = [abs(i - j) for i, j in zip(a, b)]
    e = sum(d)
    ops = (k1 + k2)
    diff = e - (ops)
    if diff <= 0:
        return abs(diff) % 2
    d.sort(reverse=True)
    while ops > 0:
        maxx = d[0]
        for i in range(len(d)):
            if d[i] == maxx:
                d[i] -= 1
                ops -= 1
            if ops == 0:
                break
    return sum(x**2 for x in d)

if __name__ == '__main__':
    _, k1, k2 = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    print(solve(k1, k2, a, b))


def solve(k1, k2, a, b):
    e = sum([abs(i - j) for i, j in zip(a, b)])
    diff = e - (k1 + k2)
    return diff if diff >= 0 else abs(diff) % 2

if __name__ == '__main__':
    _, k1, k2 = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    print(solve(k1, k2, a, b))


def solve(k1, k2, a, b):
    e = sum([(i - j)**2 for i, j in zip(a, b)])
    diff = e - (k1 + k2)
    return diff if diff >= 0 else abs(diff) % 2

if __name__ == '__main__':
    _, k1, k2 = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    print(solve(k1, k2, a, b))


import heapq

n, k, l = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
diff = []
edit = k + l

for i in range(n):
    heapq.heappush(diff, -abs(a[i]-b[i]))

while edit > 0:
    m = heapq.heappop(diff) + 1
    edit -= 1
    heapq.heappush(diff, m)

result = 0
for i in diff:
    result += i*i

print(result)


import heapq

n, k, l = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
diff = []
edit = k + l

for i in range(n):
    heapq.heappush(diff, -abs(a[i]-b[i]))

while edit > 0:
    m = heapq.heappop(diff)
    if m < 0:
        m += 1
    else:
        m -=1
    edit -= 1
    heapq.heappush(diff, m)

result = 0
for i in diff:
    result += i*i

print(result)


n, k, l = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
lst = [abs(x - y) for x, y in zip(a, b)]
for _ in range(k + l):
    lst.sort()
    lst[-1] = abs(lst[-1] - 1)
print(sum(elem * elem for elem in lst))


n, k, l = [int(i) for i in input().split()]
a = [int(input()) for i in range(n)]
b = [int(input()) for i in range(n)]
lst = [abs(x - y) for x, y in zip(a, b)]
for _ in range(k + l):
    lst.sort()
    lst[-1] = abs(lst[-1] - 1)
print(sum(elem * elem for elem in lst))


#zadb
from math import fabs
from collections import deque
n,k1,k2=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
raz=[fabs(i-j) for i,j in zip(A,B)]
raz.sort()
raz_raz=deque()
for i in range(n-1):
    raz_raz.append(raz[i]-raz[i+1])
K=k1+k2
S=sum(raz)
if S<=K:
    if (K-S)%2==0:print(0)
    else:print(1)
else:
    R=0
    for i in range(n-1):
        if raz_raz[i]!=0:
            if K>=raz_raz[i]*(i+1):
                K-=raz_raz[i]*(i+1)
                for j in range(i+1):
                    raz[j]-=raz_raz[i]
            else:
                krug=K//(i+1)
                ost=K%(i+1)
                for j in range(i+1):
                    if (j+1)<=ost:
                        raz[j]-=krug+1
                    else: raz[j]-=krug
                break
    print(int(sum(n**2 for n in raz)))


#zadb
from math import fabs
n,k1,k2=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
raz=[fabs(i-j) for i,j in zip(A,B)]
raz.sort()
K=k1+k2
S=sum(raz)
if S<=K:
    if (K-S)%2==0:print(0)
    else:print(1)
else:
    i=0
    while K!=0:
        if raz[i]<K:
            K-=raz[i]
            raz[i]=0
            i+=1
        else:
            raz[i]-=K
            K=0
    ans=[n**2 for n in raz]
    print(int(sum(ans)))


#zadb
from math import fabs
from collections import deque
n,k1,k2=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
raz=[fabs(i-j) for i,j in zip(A,B)]
raz.sort(reverse=True)
raz_raz=deque()
for i in range(n-1):
    raz_raz.append(raz[i]-raz[i+1])
raz_raz.append(0)
K=k1+k2
S=sum(raz)
if S<=K:
    if (K-S)%2==0:print(0)
    else:print(1)
else:
    R=0
    for i in range(n):
        if raz_raz[i]!=0:
            if K>=raz_raz[i]*(i+1):
                K-=raz_raz[i]*(i+1)
                for j in range(i+1):
                    raz[j]-=raz_raz[i]
            else:
                krug=K//(i+1)
                ost=K%(i+1)
                for j in range(i+1):
                    if (j+1)<=ost:
                        raz[j]-=krug+1
                    else: raz[j]-=krug
                break
        elif i==n-1:
            krug=K//(i+1)
            ost=K%(i+1)
            for j in range(i+1):
                if (j+1)<=ost:
                    raz[j]-=krug+1
                else: raz[j]-=krug
    print(int(sum(n**2 for n in raz)))


from math import *
n,k1,k2=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=0
c=[]
s=k1+k2
for i in range(n):
    c.append((a[i]-b[i])*(a[i]-b[i]))
m=sum(c)
while((s)):
    s-=1
    ma=c.index(max(c))
    c[ma]= (sqrt(c[ma])-1)*(sqrt(c[ma])-1)
print(int(sum(c)))


R = lambda: map(int, input().split())

n, k1, k2 = R()
k = k1 + k2
A = list(R())
B = tuple(R())
for i in range(n): A[i] = abs(A[i] - B[i])
for _ in range(k):
    idx = A.index(max(A))
    A[idx] = abs(A[idx] - 1)
s = 0
for a in A: s += a*a
print(s)


R = lambda: map(int, input().split())

n, k1, k2 = R()
a = [abs(x-y) for x,y in zip(R(), R())]
for _ in range(k1+k2):
    idx = a.index(max(a))
    a[idx] = abs(a[idx] - 1)
print(sum(x*x for x in a))


from collections import Counter

n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

k = k1 + k2

d = [abs(a[i] - b[i]) for i in range(n)]
C = Counter(d)

if sum(d) > k:
    while k > 0:
        m = max(C.keys())
        t = min(k, C[m])

        k -= t
        C[m] -= t

        if C[m] == 0:
            del C[m]
            m = max(C.keys())
            C[m] += t

        else:
            break

    ans = sum([k ** 2 * v for k, v in C.items()])
    print(ans)

else:
    print((k - sum(d)) % 2)


n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

k = k1 + k2

d = [abs(a[i] - b[i]) for i in range(n)]

if sum(d) > k:
    for i in range(k):
        m = max(d)
        d.remove(m)
        d.append(m - 1)

    ans = sum(x ** 2 for x in d)
    print(ans)

else:
    print((k - sum(d)) % 2)


from math import *
n,k1,k2=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=0
d=[]
k=k1+k2
for i in range(n):
    d.append((a[i]-b[i])*(a[i]-b[i]))
m=sum(d)
while((k)):
    k-=1
    ma=d.index(max(d))
    #m=abs(m-abs(a[ma]-b[ma])*abs(a[ma]-b[ma])+(abs(a[ma]-b[ma])-1)*(abs(a[ma]-b[ma])-1))
    d[ma]= (sqrt(d[ma])-1)*(sqrt(d[ma])-1)
print(int(sum(d)))


def main():
    n, k1, k2 = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [(abs(a[i] - b[i])) for i in range(n)]
    after = sum(c) - (k1 + k2)
    q, r = divmod(after, n)
    ans = sum([q**2 for i in range(n-r)]) + sum([(q+1)**2 for i in range(r)])
    print(ans)

if __name__ == '__main__':
    main()


def main():
    n, k1, k2 = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [(abs(a[i] - b[i])) for i in range(n)]
    s = sum(c)
    if s >= (k1 + k2):
        op = (k1 + k2)
        while op > 0:
            c = sorted(c)
            c[-1] -= 1
            op -= 1
        ans = sum([x**2 for x in c])
    else:
        after = (k1 + k2) - s
        if after % 2 == 0:
            ans = 0
        else:
            ans = 1
    print(ans)

if __name__ == '__main__':
    main()


def main():
    n, k1, k2 = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [(abs(a[i] - b[i])) for i in range(n)]
    s = sum(c)
    if s >= (k1 + k2):
        after = sum(c) - (k1 + k2)
        q, r = divmod(after, n)
        ans = sum([q**2 for i in range(n-r)]) + sum([(q+1)**2 for i in range(r)])
    else:
        after = (k1 + k2) - s
        if after % 2 == 0:
            ans = 0
        else:
            ans = 1
    print(ans)

if __name__ == '__main__':
    main()


def main():
    n, k1, k2 = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [(abs(a[i] - b[i])) for i in range(n)]
    s = sum(c)
    after = abs(sum(c) - (k1 + k2))
    q, r = divmod(after, n)
    ans = sum([q**2 for i in range(n-r)]) + sum([(q+1)**2 for i in range(r)])
    print(ans)

if __name__ == '__main__':
    main()


import sys
n,k1,k2=map(int,input().split())
a=[int(i) for i in sys.stdin.readline().split()]
b=[int(i) for i in sys.stdin.readline().split()]
for i in range(n):
    a[i]=abs(a[i]-b[i])
for i in range(k1+k2):
    c=a.index(max(a))
    a[c]=abs(a[c]-1)
su=0
for i in a:
    su+=(i*i)
print(su)


import sys
n,k1,k2=map(int,input().split())
a=[int(i) for i in sys.stdin.readline().split()]
b=[int(i) for i in sys.stdin.readline().split()]
for i in range(n):
    a[i]=abs(a[i]-b[i])
for i in range(k1+k2):
    c=a.index(max(a))
    a[c]=abs(a[c]-1)
su=0
for i in a:
    su+=(i*i)
sys.stdout.write(str(su))


import sys
n,k1,k2=map(int,input().split())
a=[int(i) for i in sys.stdin.readline().split()]
b=[int(i) for i in sys.stdin.readline().split()]
for i in range(n):
    a[i]=abs(a[i]-b[i])
avg=sum(a)//n
a.sort(reverse=True);m=k1+k2
while m>0:
    if a[0]==0:
        a[0]=(m%2)
        m=0
    elif a[0]>=avg:
        for i in range(n):
            if a[i]>=avg:
                l=m
                m-=min(m,a[i]-avg)
                a[i]-=min(l,a[i]-avg)
            else:
                break
        if avg>0:avg-=1
su=0
for i in range(n):
    su+=(a[i]**2)
print(su)


import sys
n,k1,k2=map(int,input().split())
a=[int(i) for i in sys.stdin.readline().split()]
b=[int(i) for i in sys.stdin.readline().split()]
for i in range(n):
    a[i]=abs(a[i]-b[i])
avg=sum(a)//n
a.sort(reverse=True);m=k1+k2
while m>0:
    if a[0]>avg:
        for i in range(n):
            if a[i]>avg:
                l=m
                m-=min(m,a[i]-avg)
                a[i]-=min(l,a[i]-avg)
            else:
                break
    else:
        for i in range(n):
            if a[i]>=avg and a[i]!=0:
                a[i]-=1;m-=1
        avg-=1
su=0
for i in range(n):
    su+=(a[i]**2)
print(su)


n,k1,k2=[int(x)for x in input().split()[:3]]
ks1=[int(x) for x in input().split()[:n]]
ks2=[int(x) for x in input().split()[:n]]
err=[abs(ks1[i]-ks2[i]) for i in range(n)]
num=k1+k2
rest1=False
if num%2 != sum(err)%2:
    rest1=True

def kill():
    global num
    maxx=max(err)
    if maxx==0 or num==0:
        return False
    for i in range(len(err)):
        if err[i] == maxx:
            err[i]-=1
            num-=1
            if num==0:
                return False
    return True
while kill():
    pass
summ=sum([x**2 for x in err])
if summ==0 and rest1:
    print(1)
else:
    print(summ)


n,a,b=map(int,input().split())
w=a+b
l=list(map(int,input().split()))
l1=list(map(int,input().split()))
L=[]
for i in range(n) :
    L.append([abs(l[i]-l1[i]),i])
for i in range(w) :
    q=max(L,key=lambda x :x[0])
    if q[0]==0 :
        if (w-i)%2==0 :
            print(0)
        else :
            print(1)
        exit()
    L[q[1]]=[q[0]-1,q[1]]
ans=0
for i in range(n) :
    ans+=L[i][0]*L[i][0]
print(ans)


a,b,c=map(int,input().split())
k=b+c
x=list(map(int,input().split()))
y=list(map(int,input().split()))
i=0
z=[]
while i<len(x):
    z=z+[max(x[i],y[i])-min(x[i],y[i])]
    i=i+1
z.sort()
i=0
while i<k:
    if z[len(z)-1]!=0:
        z[len(z)-1]=z[len(z)-1]-1
    else:
        if (k-i)%2==1:
            z=[1]
        break
    z.sort()
    i=i+1
s=0
for elem in z:
    s=s+elem**2
print (s)


[n, k1, k2] = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(n)]

for i in range(n):
    c[i] = a[i] - b[i] if a[i] > b[i] else b[i] - a[i]
c.sort(reverse=True)

k = k1 + k2
while k > 0:
    i = 0
    while i != n-1 and c[i] <= c[i+1]:
        i += 1
    c[i] = abs(c[i] - 1)
    k -= 1

result = 0
for x in c:
    result += x*x
print(result)


[n, k1, k2] = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(n)]

for i in range(n):
    c[i] = a[i] - b[i] if a[i] < b[i] else b[i] - a[i]
c.sort()

k = k1 + k2
while k > 0:
    i = 0
    while i != n-1 and c[i] >= c[i+1]:
        i += 1
    c[i] += 1
    k -= 1

result = 0
for x in c:
    result += x*x
print(result)


import heapq
n, k1, k2 = map(int, input().split())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
dis = []

for i in range(n):
    dis.append(0 - abs(list1[i]-list2[i]))

heapq.heapify(dis)

# print(dis)
num = k1 + k2

while num > 0 :
    tmp = heapq.heappop(dis)
    if(tmp == 0):
        break
    tmp += 1
    heapq.heappush(dis, tmp)
    num -= 1

if(num > 0):
    if(num % 2 == 1):
        print(1)
    else:
        print(0)
else:
    num = 0
    for i in dis:
        num += i**2
    print(num)


n, k1, k2 = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))

assert n == len(a)
assert n == len(b)

c = []

for i in range(n):
    c.append(abs(a[i] - b[i]))

c.sort(reverse=True)

k = k1 + k2

while k:
    c[0] = c[0] - 1 if c[0] > 0 else c[0] + 1
    k -= 1
    c.sort(reverse=True)

ans = sum(l ** 2 for l in c)
print(ans)


n, k1, k2 = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))

assert n == len(a)
assert n == len(b)

c = []

for i in range(n):
    c.append(abs(a[i] - b[i]))

c.sort(reverse=True)

k = k1 + k2

while k:
    c[0] -= 1
    k -= 1
    c.sort(reverse=True)

ans = sum(l ** 2 for l in c)
print(ans)


import heapq

def read():
    return [int(v) for v in input().split()]

def main():
    n, k1, k2 = read()
    k = k1 + k2
    a = read()
    b = read()
    c = [-abs(a - b) for (a, b) in zip(a, b)]
    heapq.heapify(c)
    while k:
        top = heapq.heappop(c)
        if top < 0:
            top += 1
            heapq.heappush(c, top)
        else:
            break
        k -= 1
    if k > 0:
        print(k%2)
        return
    print(sum(a*a for a in c))

if __name__ == '__main__':
    main()


n, k1, k2 = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = [abs(a[i] - b[i]) for i in range(n)]
for i in range(k1):
    ind = d.index(max(d))
    d[ind] = abs(d[ind] - 1)
for i in range(k2):
    ind = d.index(max(d))
    d[ind] = abs(d[ind] - 1)
s = 0
for i in range(n):
    s += d[i] ** 2
print(s)


n, k1, k2 = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = [abs(a[i] - b[i]) for i in range(n)]
for i in range(k1):
    ind = d.index(max(d))
    d[ind] -= 1
for i in range(k2):
    ind = d.index(max(d))
    d[ind] -= 1
s = 0
for i in range(n):
    s += d[i] ** 2
print(s)


n, k1, k2 = input().split()
a = input().split()
b = input().split()
c = [abs(int(a[i])-int(b[i])) for i in range(int(n))]
for i in range(int(k1)+int(k2)):
   c.sort()
   c[int(n)-1] = abs(c[int(n)-1] - 1)
e = 0
for i in range(int(n)):
   e += c[i]**2
print(e)


n, k1, k2 = input().split()
a = input().split()
b = input().split()
c = [abs(int(a[i])-int(b[i])) for i in range(int(n))]
for i in range(int(k1)+int(k2)):
   c.sort()
   c[int(n)-1] -= 1
e = 0
for i in range(int(n)):
   e += c[i]**2
print(e)


from queue import PriorityQueue as PQ

N, kA, kB = [int(c) for c in input().split(" ")]
A = [int(c) for c in input().split(" ")]
B = [int(c) for c in input().split(" ")]

pq = PQ()
for i in range(N):
    pq.put(-abs(A[i]-B[i]))

for i in range(kA+kB):
    max_value = pq.get()
    # print("Get %d from PQ" % (-max_value))
    if max_value == 0: pq.put(-1)
    else: pq.put(max_value + 1)

error = 0
while not pq.empty():
    error += pq.get() ** 2

print(error)


from queue import PriorityQueue as PQ

N, kA, kB = [int(c) for c in input().split(" ")]
A = [int(c) for c in input().split(" ")]
B = [int(c) for c in input().split(" ")]

pq = PQ()
for i in range(N):
    pq.put(-abs(A[i]-B[i]))

for i in range(kA+kB):
    max_value = pq.get()
    # print("Get %d from PQ" % (-max_value))
    # if max_value == 0: break
    pq.put(max_value + 1)

error = 0
while not pq.empty():
    error += pq.get() ** 2

print(error)


if __name__ == '__main__':
    n, k1, k2 = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    delta = sorted([[abs(a[i] - b[i]), i, 1 if b[i] > a[i] else 0] for i in range(len(a))], key=lambda x: -x[0])
    #print(delta)

    ks = [k1, k2]
    for k in ks:
        i = 0
        while True:
            j = i + 1
            while j < len(delta) and delta[j][0] == delta[i][0]:
                j += 1
            for t in range(i, j)[::-1]:
                if k == 0:
                    break
                delta[t][0] = abs(delta[t][0]) - 1
                k -= 1
            if k <= 0:
                break
    print(sum([delta[i][0] ** 2 for i in range(len(delta))]))


def heapify(a, i):
    left = 2 * i + 1
    right = 2 * i + 2
    largest = i

    if left < len(a) and a[left] > a[largest]:
        largest = left
    if right < len(a) and a[right] > a[largest]:
        largest = right

    if largest != i:
        a[largest], a[i] = a[i], a[largest]
        heapify(a, largest)

def build_heap(a):
    heap = a[::]
    for i in range(len(a) // 2)[::-1]:
        heapify(heap, i)
    return heap

def decrease_root(a, value):
    a[0] = abs(abs(a[0]) - value)
    heapify(a, 0)

if __name__ == '__main__':
    n, k1, k2 = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    delta_heap = build_heap([abs(a[i] - b[i]) for i in range(len(a))])

    k = k1 + k2

    while k > 0:
        decrease_root(delta_heap, 1)
        k -= 1

    print(sum([delta_heap[i] ** 2 for i in range(len(delta_heap))]))


def heapify(a, i):
    left = 2 * i + 1
    right = 2 * i + 2
    largest = i

    if left < len(a) and a[left] > a[largest]:
        largest = left
    if right < len(a) and a[right] > a[largest]:
        largest = right

    if largest != i:
        a[largest], a[i] = a[i], a[largest]
        heapify(a, largest)

def build_heap(a):
    heap = a[::]
    for i in range(len(a) // 2)[::-1]:
        heapify(heap, i)
    return heap

def decrease_root(a, value):
    a[0] = abs(a[0]) - value
    heapify(a, 0)

if __name__ == '__main__':
    n, k1, k2 = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    delta_heap = build_heap([abs(a[i] - b[i]) for i in range(len(a))])

    k = k1 + k2

    while k > 0:
        decrease_root(delta_heap, 1)
        k -= 1

    print(sum([delta_heap[i] ** 2 for i in range(len(delta_heap))]))


from math import *
n,k,k1=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
m=0
d=[]
s=k1+k
"""append"""
for i in range(n):
    d.append((A[i]-B[i])**2)
m=sum(d)
while((s)):
    s-=1
    ind=d.index(max(d))
    d[ind]= (sqrt(d[ind])-1)**2
print(int(sum(d)))


n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [abs(a[i]-b[i]) for i in range(n)]
k = k1 + k2
for _ in range(k):
    mx = max(d)
    id = d.index(mx)
    if mx == 0:
        d[id] += 1
    else:
        d[id] -= 1
print (sum(map(lambda x: x ** 2, d)))


n, k1, k2 = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

e = []
for i in range(n):
    e.append(abs(a1[i]-a2[i]))
#print(e)

for k in range(k1+k2):
    e[e.index(max(e))] = abs(max(e) - 1)

print(sum(i * i for i in e))


import operator

n,k1,k2 = map(int,input().split(" "))
arrayA = list(map(int,input().split(" ")))
arrayB = list(map(int,input().split(" ")))

arraydiff = list(map(operator.sub,arrayA,arrayB))
arraydiff = list(map(abs,arraydiff))

for i in range(k1+k2):
	arraydiff[arraydiff.index(max(arraydiff))] -= 1
print(sum(map(lambda x:x*x,arraydiff)))


import operator

n,k1,k2 = map(int,input().split(" "))
arrayA = list(map(int,input().split(" ")))
arrayB = list(map(int,input().split(" ")))

arraydiff = list(map(operator.sub,arrayA,arrayB))
arraydiff = list(map(abs,arraydiff))

for i in range(k1+k2):
	index = arraydiff.index(max(arraydiff))
	if arraydiff[index] == 0:
		arraydiff[index] += 1
	else:
		arraydiff[index] -= 1
print(sum(map(lambda x:x*x,arraydiff)))


# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 08:31:20 2020

@author: Diego
"""
from queue import PriorityQueue

n,k1,k2 = list(map(int, (input().split())))
a = list(map(int, (input().split())))
b = list(map(int, (input().split())))
c = PriorityQueue()

for i in range(n):
    dif = a[i] - b[i]
    c.put((abs(dif)*-1,i))
for e in range(k1 + k2):
    val,pos = c.get()
    if(val >= 0):
        c.put((val-1,pos))
    else:
        c.put((val+1,pos))
suma = 0
for i in range(n):
    a = c.get()
    suma += a[0]**2
print(suma)


# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 08:31:20 2020

@author: Diego
"""
from queue import PriorityQueue

n,k1,k2 = list(map(int, (input().split())))
a = list(map(int, (input().split())))
b = list(map(int, (input().split())))

c = PriorityQueue()

for i in range(n):
    dif = a[i] - b[i]
    c.put((abs(dif)*-1,i))
for e in range(k1 + k2):
    val,pos = c.get()
    c.put((val+1,pos))
suma = 0
for i in range(n):
    a = c.get()
    suma += a[0]**2
print(suma)


nrazmer, k1operationsA, k2operationsB = map(int, input().split())
myListA = list(map(int, input().split()))
myListB = list(map(int, input().split()))
diffList = []
for i in range(0, nrazmer):
    a = myListA[i]
    b = myListB[i]
    if a == b:
        i = i
    else:
        diff = abs(a - b)
        diffList.append(diff)
totalOps = k1operationsA + k2operationsB
diffList.sort()
diffList.reverse()
while totalOps > 0:
    diffList[0] -= 1
    diffList.sort()
    diffList.reverse()
    totalOps -= 1
errorSum = 0
for j in range(0, len(diffList)):
    errorSum += (diffList[j]) * diffList[j]
print(errorSum)


nrazmer, k1operationsA, k2operationsB = map(int, input().split())
myListA = list(map(int, input().split()))
myListB = list(map(int, input().split()))
diffList = []
for i in range(0, nrazmer):
    a = myListA[i]
    b = myListB[i]
    diff = abs(a - b)
    diffList.append(diff)
totalOps = k1operationsA + k2operationsB
diffList.sort()
diffList.reverse()
while totalOps > 0 and diffList[0] > 0:
    diffList[0] -= 1
    diffList.sort()
    diffList.reverse()
    totalOps -= 1
if diffList[0] == 0 and totalOps > 0:
    if totalOps % 2 == 1:
        diffList[0] = 1
    else:
        diffList[0] = 0
errorSum = 0
for j in range(0, len(diffList)):
    errorSum += (diffList[j]) * diffList[j]
print(errorSum)


nrazmer, k1operationsA, k2operationsB = map(int, input().split())
myListA = list(map(int, input().split()))
myListB = list(map(int, input().split()))
diffList = []
for i in range(0, nrazmer):
    a = myListA[i]
    b = myListB[i]
    diff = abs(a - b)
    diffList.append(diff)
totalOps = k1operationsA + k2operationsB
diffList.sort()
diffList.reverse()
while totalOps > 0 and diffList[0] > 0:
    diffList[0] -= 1
    diffList.sort()
    diffList.reverse()
    totalOps -= 1
errorSum = 0
for j in range(0, len(diffList)):
    errorSum += (diffList[j]) * diffList[j]
print(errorSum)


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int a[2004032];
int b[200403];
int ff[200403];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(ff,0,sizeof(ff));
		int n;
		int num=0;
		int f=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			a[x]++;
			if(a[x]>=4)
			{
				f=x;
				break;
			}
			if(a[x]>=2&&!ff[x])
			{
				b[++num]=x;
				ff[x]=1;
			}
		}
		int minn=2;
		for(int j=1;j<num;j++)
		{
			minn=min(minn,b[j+1]/b[j]);
		}
		if(minn==2&&f)
		{
			for(int j=0;j<=3;j++)
			printf("%d ",f);
			cout<<endl;
			continue;
		}
		//cout<<num<<"***";
		sort(b+1,b+num+1);

		for(int j=1;j<num;j++)
		{
			if(b[j+1]/b[j]==minn)
			{
				printf("%d %d %d %d\n",b[j],b[j],b[j+1],b[j+1]);
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int a[2004032];
int b[200403];
int ff[200403];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(ff,0,sizeof(ff));
		int n;
		int num=0;
		int f=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			a[x]++;
			if(a[x]>=4)
			{
				f=x;
				break;
			}
			if(a[x]>=2&&!ff[x])
			{
				b[++num]=x;
				ff[x]=1;
			}
		}
		if(f)
		{
			for(int j=0;j<=3;j++)
			printf("%d ",f);
			cout<<endl;
			continue;
		}
		//cout<<num<<"***";
		sort(b+1,b+num+1);
		int minn=120040321;
		for(int j=1;j<num;j++)
		{
			minn=min(minn,b[j+1]/b[j]);
		}
		for(int j=1;j<num;j++)
		{
			if(b[j+1]/b[j]==minn)
			{
				printf("%d %d %d %d\n",b[j],b[j],b[j+1],b[j+1]);
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int a[2004032];
int b[200403];
int ff[200403];

inline int read()
{
	int date=0,f=1;
	char c=getchar();
	while('0'>c||c>'9')
	{
		if(c=='-')
		f=-1;
		c=getchar();
	}
	while('0'<=c&&c<='9')
	{
		date=date*10+c-'0';
		c=getchar();
	}
	return date*f;
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
	//	memset(ff,0,sizeof(ff));
		int n;
		int num=0;
		int f=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			int x;
			x=read();
			a[x]++;
			if(a[x]>=4)
			{
				f=x;
			//	break;
			}
			if(a[x]==2)
			{
				b[++num]=x;
				ff[x]=1;
			}
		}
		int minn=22000001;
		sort(b+1,b+num+1);
		for(int j=1;j<num;j++)
		{
			minn=min(minn,b[j+1]/b[j]+b[j]/b[j+1]);
		}
		if(minn>=2&&f)
		{
			for(int j=0;j<=3;j++)
			printf("%d ",f);
			cout<<endl;
			continue;
		}
	    //cout<<minn<<" "<<b[1]<<" "<<b[2]<<"******";
		//cout<<num<<"***";
		//cout<<"233"<<endl;
		for(int j=1;j<num;j++)
		{
			if(b[j+1]/b[j]+b[j]/b[j+1]==minn)
			{
				printf("%d %d %d %d\n",b[j],b[j],b[j+1],b[j+1]);
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int a[2004032];
int b[200403];
int ff[200403];

inline int read()
{
	int date=0,f=1;
	char c=getchar();
	while('0'>c||c>'9')
	{
		if(c=='-')
		f=-1;
		c=getchar();
	}
	while('0'<=c&&c<='9')
	{
		date=date*10+c-'0';
		c=getchar();
	}
	return date*f;
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(ff,0,sizeof(ff));
		int n;
		int num=0;
		int f=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			int x;
			x=read();
			a[x]++;
			if(a[x]>=4)
			{
				f=x;
			//	break;
			}
			if(a[x]>=2&&!ff[x])
			{
				b[++num]=x;
				ff[x]=1;
			}
		}
		int minn=22000001;
		sort(b+1,b+num+1);
		for(int j=1;j<num;j++)
		{
			minn=min(minn,b[j+1]/b[j]);
		}
		if(minn>=1&&f)
		{
			for(int j=0;j<=3;j++)
			printf("%d ",f);
			cout<<endl;
			continue;
		}
	    //cout<<minn<<" "<<b[1]<<" "<<b[2]<<"******";
		//cout<<num<<"***";
		//cout<<"233"<<endl;
		for(int j=1;j<num;j++)
		{
			if(b[j+1]/b[j]==minn)
			{
				printf("%d %d %d %d\n",b[j],b[j],b[j+1],b[j+1]);
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int a[2004032];
int b[200403];
int ff[200403];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(ff,0,sizeof(ff));
		int n;
		int num=0;
		int f=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			a[x]++;
			if(a[x]>=4)
			{
				f=x;
			//	break;
			}
			if(a[x]>=2&&!ff[x])
			{
				b[++num]=x;
				ff[x]=1;
			}
		}
		int minn=22000001;
		sort(b+1,b+num+1);
		for(int j=1;j<num;j++)
		{
			minn=min(minn,b[j+1]/b[j]);
		}
		if(minn>=2&&f)
		{
			for(int j=0;j<=3;j++)
			printf("%d ",f);
			cout<<endl;
			continue;
		}
	    //cout<<minn<<" "<<b[1]<<" "<<b[2]<<"******";
		//cout<<num<<"***";
		//cout<<"233"<<endl;
		for(int j=1;j<num;j++)
		{
			if(b[j+1]/b[j]==minn)
			{
				printf("%d %d %d %d\n",b[j],b[j],b[j+1],b[j+1]);
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

int a[2004032];
int b[200403];
int ff[200403];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(ff,0,sizeof(ff));
		int n;
		int num=0;
		int f=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			a[x]++;
			if(a[x]>=2&&!ff[x])
			{
				b[++num]=x;
				ff[x]=1;
			}
		}
		//cout<<num<<"***";
		sort(b+1,b+num+1);
		int minn=120040321;
		for(int j=1;j<num;j++)
		{
			minn=min(minn,b[j+1]/b[j]);
		}
		for(int j=1;j<num;j++)
		{
			if(b[j+1]/b[j]==minn)
			{
				printf("%d %d %d %d\n",b[j],b[j],b[j+1],b[j+1]);
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e4+50;
map<int,int>ma;
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        ma.clear();
        for(int i=0;i<n;i++){
            cin>>a;
            ma[a]++;
        }
        map<int,int>::iterator it=ma.begin();
        double p=1.0*maxn,temp1=1.0*maxn,temp2=1.0*maxn,temp3=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        while(it!=ma.end()){
            if((*it).second>=4){
                u=(*it).first;
                c=(*it).first;
                temp3=(u*u)/(u*4.0);
                if(temp3<p){p=temp3;a=u;b=u;}
            }
            else if((*it).second>=2){
                c=(*it).first;
                if(b!=maxn){
                    temp1=c*b/2.0*(c+b);
                    if(temp1<p){p=temp1;a=b;b=c;}
                    else b=c;
                }
                else b=c;
            }
            it++;
        }
        cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn],si[maxn];
int t,n;
int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=inf,temp=inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        int cnt2=0;
        for(int i=0;i<n;i++){
            cin>>m;
            sum[m]++;
            if(sum[m]==4){
                f=true;
                a=b=m;
            }
            if(sum[m]==2){//过了就不加了
                num[cnt2]=m;
                cnt2++;
            }
        }
        if(f){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            sort(num,num+cnt2);
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=(double)c/u+(double)u/c;
                if(temp<p){
                    p=temp;
                    a=c;b=u;
                }
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn],si[maxn];
int t,n;
int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=inf,temp=inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        int cnt2=0;
        for(int i=0;i<n;i++){
            cin>>m;
            sum[m]++;
            if(sum[m]==4){
                f=true;
                a=b=m;
            }
            if(sum[m]==2){//过了就不加了
                num[cnt2++]=m;
            }
        }
        if(f){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            sort(num,num+cnt2);
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn],si[maxn];
int t,n;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=inf,temp=inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        int cnt2=0;
        for(int i=0;i<n;i++){
            cin>>m;
            sum[m]++;
            if(sum[m]==4){
                f=true;
                a=b=m;
            }
            if(sum[m]==2){//过了就不加了
                num[cnt2++]=m;
            }
        }
        if(f){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            sort(num,num+cnt2);
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
int sum[maxn];
int num[maxn];
bool cmp(int a,int b){
    return a>b;
}
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
            if(sum[a]>=4){
                a=b=a;
                p=16;
            }
        }
        if(p==16){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else {
            int cnt=0;
            for(int i=0;i<maxn;i++){
                if(sum[i]>=2)num[cnt++]=i;
            }
            c=num[0];
            for(int i=1;i<cnt;i++){
                u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
                c=u;
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
int sum[maxn];
int num[maxn];
bool cmp(int a,int b){
    return a>b;
}
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
            if(sum[a]>=4){
                a=b=a;
                p=16;
            }
        }
            int cnt=0;
            for(int i=0;i<maxn;i++){
                if(sum[i]>=2)num[cnt++]=i;
            }
            for(int i=1;i<cnt;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e4+50;
map<int,int>ma;
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        ma.clear();
        for(int i=0;i<n;i++){
            cin>>a;
            ma[a]++;
        }
        map<int,int>::iterator it=ma.begin();
        double p=1.0*maxn,temp1=1.0*maxn,temp2=1.0*maxn,temp3=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        while(it!=ma.end()){
            if((*it).second>=4){
                u=(*it).first;c=(*it).first;
                temp3=(u*u)/(u*4.0);
                if(temp3<p){p=temp3;a=b=u;}
            }
            else if((*it).second>=2){
                    c=(*it).first;
                if(b!=maxn){
                    temp1=c*b/2.0*(c+b);
                    if(temp1<p){p=temp1;a=b;b=c;}
                }
                else b=c;
            }
            it++;
        }
        cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
int sum[maxn],num[maxn];
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
        }
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        int cnt=0;
        for(int i=0;i<maxn;i++){
            if(sum[i]>=4){
                a=b=i;
                p=16;
                break;
            }
            else if(sum[i]>=2)num[cnt++]=i;
        }
        if(p==16){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else {
            sort(num,num+cnt);
            for(int i=0;i<cnt;i++){
                u=num[i];
                if(c!=maxn){
                    temp=(4.0*(u+c)*(u+c))/(u*c);
                    if(temp<p){p=temp;a=c;b=u;}
                    else c=u;
                }
                else c=u;
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn];
int t,n;
int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        double p=(double)inf,temp=(double)inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        int cnt2=0;
        for(int i=0;i<n;i++){
            cin>>m;
            sum[m]++;
            if(sum[m]==4){
                f=true;
                a=b=m;
            }
            if(sum[m]==2){//过了就不加了
                num[cnt2]=m;
                cnt2++;
            }
        }
        if(f){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            sort(num,num+cnt2);
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=4.0*((double)c/u+(double)u/c);
                if(temp<p){
                    p=temp;
                    a=c;b=u;
                }
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e4+50;
map<int,int>ma;
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        ma.clear();
        for(int i=0;i<n;i++){
            cin>>a;
            ma[a]++;
        }
        map<int,int>::iterator it=ma.begin();
        double p=1.0*maxn,temp1=1.0*maxn,temp2=1.0*maxn,temp3=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        /*while(it!=ma.end()){
            cout<<(*it).first<<endl;
            it++;
        }
        it=ma.begin();*/
        while(it!=ma.end()){
            if((*it).second>=4){
                u=(*it).first;
                if(p>16.0){p=16.0;a=u;b=u;break;}
                else b=u;
            }
            else if((*it).second>=2){//pre==c  now==u
                u=(*it).first;
                if(c!=maxn){
                    temp1=(4.0*(u+c)*(u+c))/(u*c);
                    //cout<<c<<" "<<u<<" "<<temp1<<endl;
                    if(temp1<p){p=temp1;a=c;b=u;}
                    else c=u;
                }
                else c=u;
            }
            it++;
        }
        cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
map<int,int>sum;
int num[maxn];
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        sum.clear();
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
            if(sum[a]>=4){
                a=b=a;
                p=16;
            }
        }
        if(p==16){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else {
            int cnt=0;
            map<int,int>::iterator it=sum.begin();
            for(;it!=sum.end();it++){
                if((*it).second>=2)num[cnt++]=(*it).first;
            }
            sort(num,num+cnt);
            c=num[0];
            for(int i=1;i<cnt;i++){
                u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
                else c=u;
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn];
int t,n;
int main(){
    //ios::sync_with_stdio(false);
    scanf("%d",&t);//cin>>t;
    while(t--){
        scanf("%d",&n);//cin>>n;
        mem0(sum,0);
        double p=(double)inf,temp=(double)inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        int cnt2=0;
        for(int i=0;i<n;i++){
            scanf("%d",&m);//cin>>m;
            sum[m]++;
            if(sum[m]==4){
                f=true;
                a=b=m;
            }
            if(sum[m]==2){//过了就不加了
                num[cnt2]=m;
                cnt2++;
            }
        }
        if(f){
            printf("%f %f %f %f\n",a,a,b,b);//cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            sort(num,num+cnt2);
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=4.0*((double)c/(double)u+(double)u/(double)c);
                if(temp<p){
                    p=temp;
                    a=c;b=u;
                }
            }
            printf("%f %f %f %f\n",a,a,b,b);//cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e4+50;
int sum[maxn],num[maxn];
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
        }
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        int cnt=0;
        for(int i=0;i<maxn;i++){
            if(sum[i]>=4){
                a=b=i;
                p=16;
                break;
            }
            else if(sum[i]>=2)num[cnt++]=i;
        }
        if(p==16){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else {
            sort(num,num+cnt);
            for(int i=0;i<cnt;i++){
                u=num[i];
                if(c!=maxn){
                    temp=(4.0*(u+c)*(u+c))/(u*c);
                    if(temp<p){p=temp;a=c;b=u;}
                    else c=u;
                }
                else c=u;
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e4+50;
map<int,int>ma;
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        ma.clear();
        for(int i=0;i<n;i++){
            cin>>a;
            ma[a]++;
        }
        map<int,int>::iterator it=ma.begin();
        double p=1.0*maxn,temp1=1.0*maxn,temp2=1.0*maxn,temp3=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        while(it!=ma.end()){
            if((*it).second>=4){
                u=(*it).first;c=(*it).first;
                temp3=(u*u)/(u*4.0);
                temp1=(a*c)/(2.0*(a+c));
                temp2=(c*b)/(2.0*(b+c));
                if(temp1<temp2){
                    if(temp1<temp3){
                        if(temp1<p){p=temp1;b=c;}
                    }
                    else if(temp3<p){p=temp3;a=b=u;}
                }
                else{
                    if(temp2<temp3){
                        if(temp2<p){p=temp2;a=c;}
                    }
                    else if(temp3<p){p=temp3;a=b=u;}
                }
            }
            else if((*it).second>=2){
                c=(*it).first;
                temp1=(a*c)/(2.0*(a+c));
                temp2=(c*b)/(2.0*(b+c));
                if(temp1<temp2){
                    if(temp1<p){p=temp1;b=c;}
                }
                else{
                    if(temp2<p){p=temp2;a=c;}
                }
            }
            it++;
        }
        cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn],si[maxn];
int t,n;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=inf,temp=inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        for(int i=0;i<n;i++){
            cin>>m;
            sum[m]++;
            if(sum[m]>=4){
                f=true;
                a=b=m;
            }
        }
        if(f){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            int cnt2=0,cnt4=0;
            for(int i=0;i<maxn;i++){
                if(sum[i]<2)continue;
                if(sum[i]>=2)num[cnt2++]=i;
            }
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
int sum[maxn];
int num[maxn];
bool cmp(int a,int b){
    return a>b;
}
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        bool f=false;
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
            if(sum[a]>=4){
                a=b=a;
                f=true;
            }
        }
        if(f){
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else {
            int cnt=0;
            for(int i=0;i<maxn;i++){
                if(sum[i]>=2)num[cnt++]=i;
            }
            for(int i=1;i<cnt;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn=1e4+50;
const int inf=0x3f3f3f3f;
int sum[maxn];
int num[maxn];
int t,n;
int main(){
    //ios::sync_with_stdio(false);
    scanf("%d",&t);//cin>>t;
    while(t--){
        scanf("%d",&n);//cin>>n;
        mem0(sum,0);
        double p=(double)inf,temp=(double)inf;
        int a=maxn,b=maxn,c=maxn,u=maxn,m;
        bool f=false;
        int cnt2=0;
        for(int i=0;i<n;i++){
            scanf("%d",&m);//cin>>m;
            sum[m]++;
            if(sum[m]==4){
                f=true;
                a=b=m;
            }
            if(sum[m]==2){//过了就不加了
                num[cnt2]=m;
                cnt2++;
            }
        }
        if(f){
            printf("%d %d %d %d\n",a,a,b,b);//cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
        else{
            sort(num,num+cnt2);
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=4.0*((double)c/(double)u+(double)u/(double)c);
                if(temp<p){
                    p=temp;
                    a=c;b=u;
                }
            }
            printf("%d %d %d %d\n",a,a,b,b);//cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
int sum[maxn];
int num[maxn],si[maxn];
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
        }
        int cnt2=0,cnt4=0;
        for(int i=0;i<maxn;i++){
            if(sum[i]<2)continue;
            if(sum[i]>=4)si[cnt4++]=i;
            if(sum[i]>=2&&sum[i]<4)num[cnt2++]=i;
        }
        if(cnt4>0)a=b=si[0];
        else{
            for(int i=1;i<cnt2;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
        }
        cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define eps 1e-8
#define mem0(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e4+50;
int sum[maxn];
int num[maxn];
bool cmp(int a,int b){
    return a>b;
}
int t,n,a;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        mem0(sum,0);
        float p=1.0*maxn,temp=1.0*maxn;
        int a=maxn,b=maxn,c=maxn,u=maxn;
        for(int i=0;i<n;i++){
            cin>>a;
            sum[a]++;
            if(sum[a]>=4){
                a=b=a;
                p=16;
            }
        }
            int cnt=0;
            for(int i=0;i<maxn;i++){
                if(sum[i]>=2&&sum[i]<4)num[cnt++]=i;
            }
            for(int i=1;i<cnt;i++){
                c=num[i-1];u=num[i];
                temp=(4.0*(u+c)*(u+c))/(u*c);
                if(temp<p){p=temp;a=c;b=u;}
            }
            cout<<a<<" "<<a<<" "<<b<<" "<<b<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    ios::sync_with_stdio(0);
    int T;
    cin >> T;
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin;
       int j,k,t;
       cin >> n;
       for(int i=1;i<=n;++i) cin>>a[i],b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
        cout << n << endl;
       // for(int i=1;i<=n;++i) cout << a[i]<<" ";
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*a[i]/(double)t;
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(1.0*a[i]/(double)t<imin){
                    j = k;
                    k = i;
                    imin = 1.0*a[i]/(double)t;
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             cout <<a[j]<<" "<<a[j]<<" ";
       else
             cout <<a[j]<<" "<<a[k]<<" ";
       }
       cout << endl;
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
int a[10000];
int b[1000000];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,p=0,i;
        for(i=0;i<=10000;i++)a[i]=0;
        scanf("%d",&n);
        for(i=1; i<=n; i++)
        {
            int m;
            scanf("%d",&m);
            a[m]++;
            if(a[m]==2||a[m]==4)
                b[++p]=m;
        }
        sort(b+1,b+1+p);
        int x,y;
        double minn=inf;
        for(i=1; i<p; i++)
        {
            if(b[i]==b[i+1])
            {
                x=b[i],y=b[i+1];
                break;
            }
            double m=b[i+1]*1.0/b[i];
            if(m<minn){minn=m;x=b[i];y=b[i+1];}
        }
        printf("%d %d %d %d\n",x,x,y,y);
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    ios::sync_with_stdio(0);
    int T;
    cin >> T;
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin;
       int j,k,t;
       cin >> n;
       for(int i=1;i<=n;++i) cin>>a[i],b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       // cout << n << endl;
       // for(int i=1;i<=n;++i) cout << a[i]<<" ";
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*a[i]/(double)t;
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(1.0*a[i]/(double)t<imin){
                    j = k;
                    k = i;
                    imin = 1.0*a[i]/(double)t;
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             cout <<a[j]<<" "<<a[j]<<" ";
       else
             cout <<a[j]<<" "<<a[k]<<" ";
       }
       cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
       int n,cnt = 0;
       double imin;
       int j,k,t;
       scanf("%d",&n);
       for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1){
                 b[a[i]]  = 0;
                continue;
            }
            if(b[a[i]]>=4){
                 b[a[i]]  = 0;
                flag = 1;
                j = i;
                break;
            }
            b[a[i]]  = 0;
            cnt++;
            if(cnt==1){
                j = i;
            }
            if(cnt==2){
                imin = a[i]*1.0/t;
                k = i;
            }
            if(cnt>2){
                if(a[i]*1.0/t<imin){
                    j = k;
                    k = i;
                    imin = a[i]*1.0/t;
                }
            }
            t = a[i];
       }
       for(int i=1;i<=2;++i){
        if(flag)
             printf("%d %d ",a[j],a[j]);
       else
             printf("%d %d ",a[j],a[k]);
       }
       printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin = inf;
       int j,k,t;
       scanf("%d",&n);
       for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*a[i]/(double)t;
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(1.0*a[i]/(double)t<imin){
                    j = k;
                    k = i;
                    imin = 1.0*a[i]/(double)t;
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             printf("%d %d ",a[j],a[j]);
       else
             printf("%d %d ",a[j],a[k]);
       }
       printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin;
       int j,k,t;
       scanf("%d",&n);
       for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*a[i]/(double)t+1.0*t/(double)a[i];
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(imin-(1.0*a[i]/(double)t+1.0*t/(double)a[i])>0){
                    j = k;
                    k = i;
                    imin = 1.0*a[i]/(double)t+1.0*t/(double)a[i];
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             printf("%d %d ",a[j],a[j]);
       else
             printf("%d %d ",a[j],a[k]);
       }
       printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin;
       int j,k,t;
       scanf("%d",&n);
       for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*4*(a[i]+t)*(a[i]+t)/(double(a[i]*t));
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(imin-(1.0*4*(a[i]+t)*(a[i]+t)/(double(a[i]*t)))>0){
                    j = k;
                    k = i;
                    imin = 1.0*4*(a[i]+t)*(a[i]+t)/(double(a[i]*t));
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             printf("%d %d ",a[j],a[j]);
       else
             printf("%d %d ",a[j],a[k]);
       }
       printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin;
       int j,k,t;
       scanf("%d",&n);
       for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*a[i]/(double)t;
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(imin-1.0*a[i]/(double)t>1e-6){
                    j = k;
                    k = i;
                    imin = 1.0*a[i]/(double)t;
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             printf("%d %d ",a[j],a[j]);
       else
             printf("%d %d ",a[j],a[k]);
       }
       printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1000010;
int a[maxn];
int b[10010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
       mem(b,0);
       int n,cnt = 0;
       double imin;
       int j,k,t;
       scanf("%d",&n);
       for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[a[i]]++;
       sort(a+1,a+1+n);
       n = unique(a+1,a+1+n)-a-1;
       int flag = 0;
       for(int i=1;i<=n;++i){
            if(b[a[i]]==1||b[a[i]]==3)
                continue;
            if(b[a[i]]>=4){
                flag = 1;
                j = i;
                break;
            }
            cnt++;
            if(cnt==1){
                t = a[i];
                j = i;
            }
            if(cnt==2){
                imin = 1.0*a[i]/(double)t+1.0*t/(double)a[i];
                k = i;
                t = a[i];
            }
            if(cnt>2){
                if(imin-(1.0*a[i]/(double)t+1.0*t/(double)a[i])>0){
                    j = k;
                    k = i;
                    imin = 1.0*a[i]/(double)t+1.0*t/(double)a[i];
                }
                t = a[i];
            }
       }
       for(int i=1;i<=2;++i){
        if(flag)
             printf("%d %d ",a[j],a[j]);
       else
             printf("%d %d ",a[j],a[k]);
       }
       printf("\n");
    }
    return 0;
}