#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define digits(n)          (floor(log10(n))+1;
#define max3(a,b,c)        max(a,max(b,c))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

int a[200005];

int main()
{

    int t,n,x,i;
    cin>>t;
    while(t--){
        cin>>n;
        int flag = 0;
        for(i=1;i<=n;i++)a[i]=0;
        for(i=1;i<=n;i++){
            cin>>x;
            if(a[x]){
                if(i-a[x]>1)flag=1;
            }
            a[x]=i;
        }
        if(flag==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


#include <iostream>
#include <vector>

using namespace std ;

int main (){
	int n , ai;
	int buff ;
	int t ;
	cin >> t ;
	while (--t+1){
		cin >> n ;
		int buff=0;
		string r = "YES";
		while(--n){

			cin >> ai ;
			buff+= ai ;
		}
		//cout <<"buff :"<<buff<<'\n';
		if (buff%2) r = "NO" ;
		cout <<r<<'\n';
	}
}


#include <iostream>
#include <vector>

using namespace std ;

int main (){
	int n , ai;
	int buff ;
	int t ;
	cin >> t ;
	while (--t){
		cin >> n ;
		cin >> ai ;

		buff=ai%2 ;
		string r = "YES";
		while(--n){

			cin >> ai ;
			if(buff!=ai%2) r="NO";
		}
		cout <<r<<"\n";
	}
}


#include <iostream>

#include <vector>
using namespace std ;

bool palCheck(int*arr , int n ){

	if (n = 4) {
		if ((arr[0]==arr[3])&&(arr[1]==arr[2])){

			return true ;
		}
	}
	if(arr[n-1]==arr[n-3]){
			return true ;
		}

	for ( int i = 0 ; i < n-4 ; ++i){

		if(arr[i]==arr[i+2]){
			return true ;
		}

		if ((arr[i]==arr[i+3])&&(arr[i+1]==arr[i+2])){

			return true ;
		}
	}
	return false ;

}

void printArr (int * arr ,int  n ){
	cout << "ARRAY : " ;
	for ( int i = 0 ; i < n ; ++i){
		cout << arr[i] << " " ;
	}
	cout << endl ;
}

int main (){
	int t , n , el ;

	//freopen("file","r",stdin);

	cin >> t ;

	for (int i = 0 ; i < t ; ++i ){

		int  arr [5005];

		cin >> n ;
		for (int  j = 0 ; j < n ; ++j ){
			cin >> el ;
			arr[j]=el;
		}
		printArr(arr , n);

		if (palCheck ( arr , n)){
			cout << "YES"<< "\n" ;
		}
		else {
			cout << "NO"<< "\n" ;
			}
	}

}


#include <iostream>
#include <vector>

using namespace std ;

int main (){
	int n , ai;
	int buff ;
	int t ;
	cin >> t ;
	while (--t+1){
		cin >> n ;
		int buff=0;
		string r = "YES";
		while(--n+1){

			cin >> ai ;
			buff+= ai ;
		}
		//cout <<"buff :"<<buff<<'\n';
		if (buff%2) r = "NO" ;
		cout <<r<<'\n';
	}
}


#include <iostream>

#include <vector>
using namespace std ;

bool palCheck(int*arr , int n ){

	if (n = 4) {
		if ((arr[0]==arr[3])&&(arr[1]==arr[2])){

			return true ;
		}
	}
	if(arr[n-1]==arr[n-3]){
			return true ;
		}

	for ( int i = 0 ; i < n-4 ; ++i){

		if(arr[i]==arr[i+2]){
			return true ;
		}

		if ((arr[i]==arr[i+3])&&(arr[i+1]==arr[i+2])){

			return true ;
		}
	}
	return false ;

}

void printArr (int * arr ,int  n ){
	cout << "ARRAY : " ;
	for ( int i = 0 ; i < n ; ++i){
		cout << arr[i] << " " ;
	}
	cout << endl ;
}

int main (){
	int t , n , el ;

	//freopen("file","r",stdin);

	cin >> t ;

	for (int i = 0 ; i < t ; ++i ){

		int  arr [5005];

		cin >> n ;
		for (int  j = 0 ; j < n ; ++j ){
			cin >> el ;
			arr[j]=el;
		}

		if (palCheck ( arr , n)){
			cout << "YES"<< "\n" ;
		}
		else {
			cout << "NO"<< "\n" ;
			}
	}

}


#include <iostream>

#include <vector>
using namespace std ;

bool palCheck(int*arr , int n ){

	if (n == 4) {
		if ((arr[0]==arr[3])&&(arr[1]==arr[2])){

			return true ;
		}
	}
	if(arr[n-1]==arr[n-3]){
			return true ;
		}

	for ( int i = 0 ; i < n-4 ; ++i){

		if(arr[i]==arr[i+2]){
			return true ;
		}

		if ((arr[i]==arr[i+3])&&(arr[i+1]==arr[i+2])){

			return true ;
		}
	}
	return false ;

}

void printArr (int * arr ,int  n ){
	cout << "ARRAY : " ;
	for ( int i = 0 ; i < n ; ++i){
		cout << arr[i] << " " ;
	}
	cout << endl ;
}

int main (){
	int t , n , el ;

	//freopen("file","r",stdin);

	cin >> t ;

	for (int i = 0 ; i < t ; ++i ){

		int  arr [5005];

		cin >> n ;
		for (int  j = 0 ; j < n ; ++j ){
			cin >> el ;
			arr[j]=el;
		}

		if (palCheck ( arr , n)){
			cout << "YES"<< "\n" ;
		}
		else {
			cout << "NO"<< "\n" ;
			}
	}

}


#include <iostream>

#include <vector>
using namespace std ;

bool palCheck(int*arr , int n ){
	/*
	if (n == 4) {
		if ((arr[0]==arr[3])&&(arr[1]==arr[2])){

			return true ;
		}
	}
	*/
	if(arr[n-1]==arr[n-3]){
			return true ;
		}

	for ( int i = 0 ; i < n-3 ; ++i){

		if(arr[i]==arr[i+2]){
			return true ;
		}

		if ((arr[i]==arr[i+3])&&(arr[i+1]==arr[i+2])){

			return true ;
		}
	}
	return false ;

}

void printArr (int * arr ,int  n ){
	cout << "ARRAY : " ;
	for ( int i = 0 ; i < n ; ++i){
		cout << arr[i] << " " ;
	}
	cout << endl ;
}

int main (){
	int t , n , el ;

	//freopen("file","r",stdin);

	cin >> t ;

	for (int i = 0 ; i < t ; ++i ){

		int  arr [5005];

		cin >> n ;
		for (int  j = 0 ; j < n ; ++j ){
			cin >> el ;
			arr[j]=el;
		}

		if (palCheck ( arr , n)){
			cout << "YES"<< "\n" ;
		}
		else {
			cout << "NO"<< "\n" ;
			}
	}

}


#include <iostream>

#include <set>

#include <vector>
using namespace std ;

bool wrongPalCheck(int*arr , int n ){

	// n = 3
	if(arr[n-1]==arr[n-3]){
			return true ;
		}

	// n >= 4
	for ( int i = 0 ; i < n-3 ; ++i){

		if(arr[i]==arr[i+2]){
			return true ;
		}

		if ((arr[i]==arr[i+3])&&(arr[i+1]==arr[i+2])){

			return true ;
		}
	}
	return false ;
}

bool palCheck(int* arr , int n ){
	set <int> s ;
	for ( int i = 0 ; i < n-2 ; ++i){

		for (int j = i+2 ; j<n ; ++j){

			if(arr[j]==arr[i]){
				return true ;
			}
		}

	}
	return false ;

}

void printArr (int * arr ,int  n ){
	cout << "ARRAY : " ;
	for ( int i = 0 ; i < n ; ++i){
		cout << arr[i] << " " ;
	}
	cout << endl ;
}

int main (){
	int t , n , el ;

	//freopen("file","r",stdin);

	cin >> t ;

	for (int i = 0 ; i < t ; ++i ){

		int  arr [5005];

		cin >> n ;
		for (int  j = 0 ; j < n ; ++j ){
			cin >> el ;
			arr[j]=el;
		}

		if (palCheck ( arr , n)){
			cout << "YES"<< "\n" ;
		}
		else {
			cout << "NO"<< "\n" ;
			}
	}

}


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

using namespace std;
int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		vector<int> pos(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
			pos[i] = i;
		}
		for(int i = 0; i < num - 1; i++){
			for(int j = i + 1; j < num; j++){
				if(val[j] < val[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
			}
		}
		for(int i = 0; i < num; i++){
			if(val[i + 1] == val[i]){
				int floor = pos[i + 1], ceil = pos[i];
				if(floor - ceil == 2){ //type: aba
					bol = true;
					break;
				}
				else if(floor - ceil == 1)	continue;
				else{
					bool tempbol = true;
					for(int j = ceil + 1; j < floor; j++){
						if(val[j] != val[floor - j]){
							tempbol = false;
							break;
						}
					}
					bol = tempbol;
				}
			}
		}

		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
		//vector<int>::iterator begin = v.begin();
		//vector<int>::iterator end = v.end() - 1;

	}
	return 0;
}
//1. 開第二個陣列存差值
//2. 用find找一樣的元素


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

using namespace std;
int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		vector<int> pos(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
			pos[i] = i;
		}
		for(int i = 0; i < num - 1; i++){
			for(int j = i + 1; j < num; j++){
				if(val[j] < val[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
			}
		}
		for(int i = 0; i < num - 1; i++){
			if(val[i + 1] == val[i]){
				int floor = pos[i + 1], ceil = pos[i];
				if(floor - ceil == 2){ //type: aba
					bol = true;
					break;
				}
				else if(floor - ceil == 1)	continue;
				else{
					bool tempbol = true;
					for(int j = ceil + 1; j < floor; j++){
						if(val[j] != val[floor - j]){
							tempbol = false;
							break;
						}
					}
					bol = tempbol;
				}
			}
		}

		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
		//vector<int>::iterator begin = v.begin();
		//vector<int>::iterator end = v.end() - 1;

	}
	return 0;
}
//1. 開第二個陣列存差值
//2. 用find找一樣的元素


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

using namespace std;
int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		vector<int> pos(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
			pos[i] = i;
		}
		for(int i = 0; i < num - 1; i++){
			for(int j = i + 1; j < num; j++){
				if(val[j] < val[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
				else if(val[j] == val[i] && pos[j] < pos[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
			}
		}
		for(int i = 1; i < num; i++){
			for(int k = 0; k < i; k++){
				if(val[k] == val[i]){
					int floor = pos[k], ceil = pos[i];
					if(ceil - floor == 1)	continue;
					else{
						bol = true;
						break;
					}
				}
			}

		}

		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
		//vector<int>::iterator begin = v.begin();
		//vector<int>::iterator end = v.end() - 1;

	}
	return 0;
}
//1. 開第二個陣列存差值
//2. 用find找一樣的元素


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

using namespace std;
int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		vector<int> pos(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
			pos[i] = i;
		}
		for(int i = 0; i < num - 1; i++){
			for(int j = i + 1; j < num; j++){
				if(val[j] < val[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
			}
		}
		for(int i = 1; i < num; i++){
			for(int k = 0; k < i; k++){
				if(val[k] == val[i]){
					int floor = pos[k], ceil = pos[i];
					if(floor - ceil == 2){ //type: aba
						bol = true;
						break;
					}
					else if(floor - ceil == 1)	continue;
					else{
						bool tempbol = true;
						for(int j = ceil + 1; j < floor; j++){
							if(val[j] != val[floor - j]){
								tempbol = false;
								break;
							}
						}
						bol = tempbol;
					}

				}
			}
		}

		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
		//vector<int>::iterator begin = v.begin();
		//vector<int>::iterator end = v.end() - 1;

	}
	return 0;
}
//1. 開第二個陣列存差值
//2. 用find找一樣的元素


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

using namespace std;
int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		vector<int> pos(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
			pos[i] = i;
		}
		for(int i = 0; i < num - 1; i++){
			for(int j = i + 1; j < num; j++){
				if(val[j] < val[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
			}
		}
		for(int i = 1; i < num; i++){
			for(int k = 0; k < i; k++){
				if(val[k] == val[i]){
					int floor = pos[k], ceil = pos[i];
					if(ceil - floor == 1)	continue;
					else{
						bol = true;
						break;
					}
				}
			}

		}

		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
		//vector<int>::iterator begin = v.begin();
		//vector<int>::iterator end = v.end() - 1;

	}
	return 0;
}
//1. 開第二個陣列存差值
//2. 用find找一樣的元素


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

using namespace std;
int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		vector<int> pos(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
			pos[i] = i;
		}
		for(int i = 0; i < num - 1; i++){
			for(int j = i + 1; j < num; j++){
				if(val[j] < val[i]){
					int temp = val[i];
					val[i] = val[j];
					val[j] = temp;
					temp = pos[i];
					pos[i] = pos[j];
					pos[j] = temp;
				}
			}
		}
		for(int i = 1; i < num; i++){
			if(val[i - 1] == val[i]){
				int floor = pos[i - 1], ceil = pos[i];
				if(ceil - floor == 1)	continue;
				else{
					bol = true;
					break;
				}
			}
		}

		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
		//vector<int>::iterator begin = v.begin();
		//vector<int>::iterator end = v.end() - 1;

	}
	return 0;
}
//1. 開第二個陣列存差值
//2. 用find找一樣的元素


#include <iostream>
#include <vector>
using namespace std;

int main(){
	int cases, num;
	cin >> cases;
	while(cases--){
		cin >> num;
		bool bol = false;
		vector<int> val(num);
		int temp;
		for(int i = 0; i < num; i++){
			cin >> temp;
			val[i] = temp;
		}
		for(int i = 1; i < num - 1; i++){
			if(val[i - 1] == val[i + 1]){
				bol = true;
				break;
			}
		}
		for(int i = 1; i < num - 2; i++){
			if(val[i] == val[i + 1] && val[i - 1] == val[i + 2]){
				bol = true;
				break;
			}
		}
		if(bol)	cout << "YES\n";
		else	cout << "NO\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

int main()
{
    io;
    ll i,t,c,d,temp1,temp,j,n,k,z1,flag,c1,d1,m,z,count;
    cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll> v1(n),v2(n);
       set<ll> s;
       for(i=0;i<n;i++)
       {
           cin>>v1[i];
           s.insert(v1[i]);
           v2[i]=v1[i];
       }
       sort(v2.begin(),v2.end());
       if(s.size()==n)
       cout<<"NO"<<'\n';
       else
       {   flag=0;
       count=0;
          for(i=0;i<n;i++)
          {
            if(v1[i]!=v2[i])
            {
               flag=1;
               break;
            }
            if(v1[i]==v2[i])
            count++;
          }
          if(flag==1||count==n)
          cout<<"YES"<<'\n';
          else
          cout<<"NO"<<'\n';
       }

    }

   return 0;

}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

int main()
{
    io;
    ll i,t,c,d,temp1,temp,j,n,k,z1,flag,c1,d1,m,z,count;
    cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll> v1(n),v2(n);
       set<ll> s;
       map<ll,ll> mpp;
       flag=0;
       for(i=0;i<n;i++)
       {
           cin>>v1[i];
           s.insert(v1[i]);
           v2[i]=v1[i];
           mpp[v1[i]]++;
       }
       sort(v2.begin(),v2.end());
       for(auto x:mpp)
       {
         if(x.second>=3)
         {
            flag=1;
            break;
         }
       }
       if(s.size()==n)
       cout<<"NO"<<'\n';
       else if(flag!=0)
       {
          cout<<"YES"<<'\n';
       }
       else
       {   flag=0;
          for(i=0;i<n;i++)
          {
            if(v1[i]!=v2[i])
            {
               flag=1;
               break;
            }
          }
          if(flag==1||s.size()==1)
          cout<<"YES"<<'\n';
          else
          cout<<"NO"<<'\n';
       }

    }

   return 0;

}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

int main()
{
    io;
    ll i,t,c,d,temp1,temp,j,n,k,z1,flag,c1,d1,m,z,count;
    cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll> v1(n),v2(n),v3(n);
       set<ll> s;
       map<ll,ll> mpp;
       flag=0;
       for(i=0;i<n;i++)
       {
           cin>>v1[i];
           s.insert(v1[i]);
           v2[i]=v1[i];
           mpp[v1[i]]++;
           v3[i]=v1[i];
       }
       sort(v2.begin(),v2.end());
       sort(v3.begin(), v3.end(), greater<int>());
       for(auto x:mpp)
       {
         if(x.second>=3)
         {
            flag=1;
            break;
         }
       }
       if(s.size()==n)
       cout<<"NO"<<'\n';
       else if(flag!=0)
       {
          cout<<"YES"<<'\n';
       }
       else
       {   flag=0;
       count=0;
          for(i=0;i<n;i++)
          {
            if(v1[i]==v2[i])
            {
               flag++;
               //break;
            }
            if(v3[i]==v1[i])
            count++;
          }
          //cout<<flag;
          if((flag!=n&&count!=n)||s.size()==1)
          cout<<"YES"<<'\n';
          else
          cout<<"NO"<<'\n';
       }

    }

   return 0;

}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

int main()
{
    io;
    ll i,t,c,d,temp1,temp,j,n,k,z1,flag,c1,d1,m,z,count;
    cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll> v1(n),v2(n);
       set<ll> s;
       for(i=0;i<n;i++)
       {
           cin>>v1[i];
           s.insert(v1[i]);
           v2[i]=v1[i];
       }
       sort(v2.begin(),v2.end());
       if(s.size()==n)
       cout<<"NO"<<'\n';
       else
       {   flag=0;
          for(i=0;i<n;i++)
          {
            if(v1[i]!=v2[i])
            {
               flag=1;
               break;
            }
          }
          if(flag==1)
          cout<<"YES"<<'\n';
          else
          cout<<"NO"<<'\n';
       }

    }

   return 0;

}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

int main()
{
    io;
    ll i,t,c,d,temp1,temp,j,n,k,z1,flag,c1,d1,m,z,count;
    cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll> v1(n),v2(n);
       set<ll> s;
       for(i=0;i<n;i++)
       {
           cin>>v1[i];
           s.insert(v1[i]);
           v2[i]=v1[i];
       }
       sort(v2.begin(),v2.end());
       if(s.size()==n)
       cout<<"NO"<<'\n';
       else
       {   flag=0;
          for(i=0;i<n;i++)
          {
            if(v1[i]!=v2[i])
            {
               flag=1;
               break;
            }
          }
          if(flag==1||s.size()==1)
          cout<<"YES"<<'\n';
          else
          cout<<"NO"<<'\n';
       }

    }

   return 0;

}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

int main()
{
    io;
    ll i,t,c,d,temp1,temp,j,n,k,z1,flag,c1,d1,m,z,count;
    cin>>t;
    while(t--)
    {
       cin>>n;
       vector<ll> v1(n),v2(n),v3(n);
       set<ll> s;
       map<ll,ll> mpp;
       flag=0;
       count=0;
       z=0;
       for(i=1;i<=n;i++)
       {
           cin>>c;

              if(mpp[c]!=0)
              {
                d=i-mpp[c];
                if(d>=2)
                flag=1;
                if(d==1)
                {
                  if(z!=c)
                  count=0;
                  count++;
                  z=c;

                }
                if(count>=2)
                flag=1;
                //cout<<count;
              }
              else
              {
                mpp[c]=i;
              }

       }
       //cout<<flag;
       if(flag==1)
       cout<<"YES"<<'\n';
       else if(flag==0)
       cout<<"NO"<<'\n';

    }

   return 0;

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int cas;
	cin>>cas;
	while(cas--){
		int n,h[10001]={0},found=0;
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>h[i];
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(h[i]==h[j]){
					if(j-i>1){
						found++;
					}
				}
			}
		}
		if(found==0){
			cout<<"NO\n";
		}
		else{
			cout<<"YES\n";
		}
	}
}


#include<bits/stdc++.h>
#include<string>
#include<cmath>
#define ll long long
using namespace std;

int main(){
  int t;cin>>t;
  while(t--){

    int n;cin>>n;
    int a[n],flag=0;
    for(int i=0;i<n;i++){
      cin>>a[i];
      if(i>=2 && flag==0){
        for(int j=0;j<i-1;j++){
          if(a[i]==a[j])
            flag=1;
        }
      }
    }
    if(flag==0)
      cout<<"NO"<<"\n";
    else
      cout<<"YES"<<"\n";
  }
}


#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
// Right Arrow
ostream &ra(ostream &stream){
    stream << " ------->";
    return stream;
}
int main(int argc, char *argv[])
{
    fastIO; //for fast input/output
    /******to write output and read input to and from file*****/
    // freopen("in1.txt", "r", stdin);  //freopen("output.txt", "w", stdout);
    /**************Just Trying to be better**************/
    ll tc;
    cin>>tc;
    while(tc--){

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        bool b=false;
        for(int i=0; i<n && !b; i++){
            for(int j=n-1;j>i;j--){
                if(a[i]==a[j] && (j-i)>1){
                    b=true;
                    break;
                }
            }
        }

        if(b){
            cout<<"YES";
        }else{
            cout<<"NO";
        }

        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        bool ok=false;
        if(n<=100){
            for(int i=0;i<n;i++){
                for(int j=i+2;j<n;j++){
                    if(a[i]==a[j])ok=1;
                }
            }
        }else {
            vector<int> cnt(n+1);
            for(int i=0;i<n;i++){
                if(cnt[a[i]])ok=1;
                if(i-1>=0)cnt[a[i-1]]++;
            }
        }
        if(ok)puts("YES");
        else puts("NO");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
template<typename T>
int sz(const T &a){return (int)a.size();}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin >> n;
        map<int,vector<int>> inds;
        int a;
        for (int i = 0; i < n; i++) {
            cin>>a;
            inds[a].push_back(i);
        }
        bool work=false;
        for(auto x:inds){
            if(sz(x.second)>=3){
                printf("YES\n");
                work=true;
                break;
            }
            if(sz(x.second)>=2){
                if(x.second[1]-x.second[0]>1) {
                    printf("YES\n");
                    work = true;
                    break;
                }
            }
        }
        if(!work)printf("NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

string longestPalindrome(string s) {
    if (s.size()<3) return "";
    int min_start = 0, max_len = 1;
    for (int i = 0; i < s.size();) {
      if (s.size() - i <= max_len / 2) break;
      int j = i, k = i;
      while (k < s.size()-1 && s[k+1] == s[k]) ++k; // Skip duplicate characters.
      i = k+1;
      while (k < s.size()-1 && j > 0 && s[k + 1] == s[j - 1]) { ++k; --j; } // Expand.
      int new_len = k - j + 1;
      if (new_len > max_len) { min_start = j; max_len = new_len; }
    }
    return s.substr(min_start, max_len);
}

int checkpal (string x){
    int n=x.length();
    int flag=1;
    for(int i=0;i<n/2;++i){
        if(x[i]!=x[n-i-1]){
            flag=0;
            break;
        }
    }
    return flag;
}

int trythis(string x){
    int n=x.length();
    for(int i=0;i<n;++i){
        if(i+2<=n-1){
            for(int j=i+2;j<n;++j){
                if(checkpal(x.substr(i,j-i+1)))
                    return 1;
            }
        }
    }
    return 0;
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        string x=longestPalindrome(s);
        if(trythis(s))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

int checkpal (int a[],int i,int j){
    int flag=1;
    while(i<j){
        if(a[i]!=a[j]){
            flag=0;
            break;
        }
        ++i;
        --j;
    }
    return flag;
}

int trythis(int a[],int n){
    for(int i=0;i<n;++i){
        for(int j=i+2;j<n;++j){
            if(checkpal(a,i,j))
                return 1;
        }
    }
    return 0;
}

int lps(int str[],int n)
{

   int i, j, cl;
   int L[n][n];  // Create a table to store results of subproblems

   // Strings of length 1 are palindrome of lentgh 1
   for (i = 0; i < n; i++)
      L[i][i] = 1;

    // Build the table. Note that the lower diagonal values of table are
    // useless and not filled in the process. The values are filled in a
    // manner similar to Matrix Chain Multiplication DP solution (See
    // https://www.geeksforgeeks.org/matrix-chain-multiplication-dp-8/). cl is length of
    // substring
    for (cl=2; cl<=n; cl++)
    {
        for (i=0; i<n-cl+1; i++)
        {
            j = i+cl-1;
            if (str[i] == str[j] && cl == 2)
               L[i][j] = 2;
            else if (str[i] == str[j])
               L[i][j] = L[i+1][j-1] + 2;
            else
               L[i][j] = max(L[i][j-1], L[i+1][j]);
        }
    }

    return L[0][n-1];
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        int max;
        REP(i,n){
            cin>>a[i];
        }
        if(lps(a,n)>=3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

int longestPalSubstr(string str)
{
    // get length of input string
    int n = str.size();

    // table[i][j] will be false if substring str[i..j]
    // is not palindrome.
    // Else table[i][j] will be true
    bool table[n][n];

    memset(table, 0, sizeof(table));

    // All substrings of length 1 are palindromes
    int maxLength = 1;

    for (int i = 0; i < n; ++i)
        table[i][i] = true;

    // check for sub-string of length 2.
    int start = 0;
    for (int i = 0; i < n-1; ++i)
    {
        if (str[i] == str[i+1])
        {
            table[i][i+1] = true;
            start = i;
            maxLength = 2;
        }
    }

    // Check for lengths greater than 2. k is length
    // of substring
    for (int k = 3; k <= n; ++k)
    {
        // Fix the starting index
        for (int i = 0; i < n-k+1 ; ++i)
        {
            // Get the ending index of substring from
            // starting index i and length k
            int j = i + k - 1;

            // checking for sub-string from ith index to
            // jth index iff str[i+1] to str[j-1] is a
            // palindrome
            if (table[i+1][j-1] && str[i] == str[j])
            {
                table[i][j] = true;

                if (k > maxLength)
                {
                    start = i;
                    maxLength = k;
                }
            }
        }
    }

  // cout << "Longest palindrome substring is: ";
//   printSubStr( str, start, start + maxLength - 1 );

    // return length of LPS
    return maxLength;
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        if(longestPalSubstr(s)>=3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

string longestPalindrome(string s) {
    if (s.size()<3) return "";
    int min_start = 0, max_len = 1;
    for (int i = 0; i < s.size();) {
      if (s.size() - i <= max_len / 2) break;
      int j = i, k = i;
      while (k < s.size()-1 && s[k+1] == s[k]) ++k; // Skip duplicate characters.
      i = k+1;
      while (k < s.size()-1 && j > 0 && s[k + 1] == s[j - 1]) { ++k; --j; } // Expand.
      int new_len = k - j + 1;
      if (new_len > max_len) { min_start = j; max_len = new_len; }
    }
    return s.substr(min_start, max_len);
}

int checkpal (string x){
    int n=x.length();
    int flag=1;
    for(int i=0;i<(n-1)/2;++i){
        if(x[i]!=x[n-i-1]){
            flag=0;
            break;
        }
    }
    return flag;
}

int trythis(string x){
    int n=x.length();
    for(int i=0;i<n;++i){
        if(i+2<=n-1){
            for(int j=i+2;j<n;++j){
                if(checkpal(x.substr(i,j-i+1)))
                    return 1;
            }
        }
    }
    return 0;
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        //string x=longestPalindrome(s);
        if(trythis(s))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

int longestPalSubstr(string str)
{
    int maxLength = 1; // The result (length of LPS)

    int start = 0;
    int len = str.length();

    int low, high;

    // One by one consider every character as center point of
    // even and length palindromes
    for (int i = 1; i < len; ++i)
    {
        // Find the longest even length palindrome
        // with center points as i-1 and i.
        low = i - 1;
        high = i;
        while (low >= 0 && high < len && str[low] == str[high])
        {
            if (high - low + 1 > maxLength)
            {
                start = low;
                maxLength = high - low + 1;
            }
            --low;
            ++high;
        }

        // Find the longest odd length palindrome with center
        // point as i
        low = i - 1;
        high = i + 1;
        while (low >= 0 && high < len && str[low] == str[high])
        {
            if (high - low + 1 > maxLength)
            {
                start = low;
                maxLength = high - low + 1;
            }
            --low;
            ++high;
        }
    }

    //cout<<"Longest palindrome substring is: ";
   // printSubStr(str, start, start + maxLength - 1);

    return maxLength;
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        if(longestPalSubstr(s)>=3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

int checkpal (int a[],int i,int j){
    int flag=1;
    while(i<j){
        if(a[i]!=a[j]){
            flag=0;
            break;
        }
        ++i;
        --j;
    }
    return flag;
}

int trythis(int a[],int n){
    for(int i=0;i<n;++i){
        for(int j=i+2;j<n;++j){
            if(checkpal(a,i,j))
                return 1;
        }
    }
    return 0;
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
        }
        if(trythis(a,n))
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

string longestPalindrome(string s) {
    if (s.empty()) return "";
    if (s.size() == 1) return s;
    int min_start = 0, max_len = 1;
    for (int i = 0; i < s.size();) {
      if (s.size() - i <= max_len / 2) break;
      int j = i, k = i;
      while (k < s.size()-1 && s[k+1] == s[k]) ++k; // Skip duplicate characters.
      i = k+1;
      while (k < s.size()-1 && j > 0 && s[k + 1] == s[j - 1]) { ++k; --j; } // Expand.
      int new_len = k - j + 1;
      if (new_len > max_len) { min_start = j; max_len = new_len; }
    }
    return s.substr(min_start, max_len);
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        string x=longestPalindrome(s);
        if(x.length()>=3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

string longestPalindrome(string s) {
    if (s.empty()) return "";
    if (s.size() == 1) return s;
    int min_start = 0, max_len = 1;
    for (int i = 0; i < s.size();) {
      if (s.size() - i <= max_len / 2) break;
      int j = i, k = i;
      while (k < s.size()-1 && s[k+1] == s[k]) ++k; // Skip duplicate characters.
      i = k+1;
      while (k < s.size()-1 && j > 0 && s[k + 1] == s[j - 1]) { ++k; --j; } // Expand.
      int new_len = k - j + 1;
      if (new_len > max_len) { min_start = j; max_len = new_len; }
    }
    return s.substr(min_start, max_len);
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        if(longestPalindrome(s).length()>=3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
//1 to enable Debugging, 0 to disable
#define DEBUG 0
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define SQR(x) ((x)*(x))
#if DEBUG
    #define DBG(x) cout << "> " << #x << ": " << x << endl;
#else
    #define DBG(x)
#endif
#define all(c) c.begin(), c.end()
#define pb push_back
#define present(c,x) ((c).find(x)!=(c).end())
#define sz(a) int((a).size())
#define REP(i,N) for(int i=0; i<N; i++)
#define REPx(i,x,N) for(int i=x; i<N; i++)
#define REPit(it, x) for(__typeof(x.begin()) it = x.begin(); it != x.end(); it++)
#define NOSYNC std::ios_base::sync_with_stdio(false)
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
using namespace std;

int longestPalindrome(string X, int i, int j)
{
    // base condition
    if (i > j)
        return 0;

    // if string X has only one character, it is palindrome
    if (i == j)
        return 1;

    // if last character of the string is same as the first character
    if (X[i] == X[j])
    {
        // include first and last characters in palindrome
        // and recur for the remaining substring X[i+1, j-1]
        return longestPalindrome(X, i + 1, j - 1) + 2;
    }

    // if last character of string is different to the first character

    // 1. Remove last character and recur for the remaining
    //  substring X[i, j-1]
    // 2. Remove first character and recur for the remaining
    //  substring X[i+1, j]

    // return maximum of the two values
    return max (longestPalindrome(X, i, j - 1),
                longestPalindrome(X, i + 1, j));
}

int main(){
    NOSYNC;
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int a[n];
        string s;
        int max;
        REP(i,n){
            cin>>a[i];
            s+=to_string(a[i]);
        }
        if(longestPalindrome(s,0,n-1)>=3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Test {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		Map<Integer, Integer> up = new HashMap<Integer, Integer>();
		Map<Integer, Integer> down = new HashMap<Integer, Integer>();
		Set<Integer> colors = new HashSet<Integer>();
		int n = nextInt();
		for(int i=0;i<n;i++)
		{
			int c1 = nextInt();
			int c2 = nextInt();
			colors.add(c1);
			colors.add(c2);
			if(up.containsKey(c1))
			{
				up.put(c1,up.get(c1)+1);
			}
			else
			{
				up.put(c1,1);
			}
			if(down.containsKey(c2))
			{
				down.put(c2,down.get(c2)+1);
			}
			else
			{
				down.put(c2,1);
			}
		}
		int res = Integer.MAX_VALUE;
		int need = (n+1)/2;
		for(int i:colors)
		{
			int gotu=0;
			int gotd=0;
			if(up.containsKey(i))
			{
				gotu=up.get(i);
			}
			if(down.containsKey(i))
			{
				gotd=down.get(i);
			}
			if(gotu+gotd>=need)
			{
				int curr = need-gotu;
				if(curr<0)
					curr=0;
				if(curr<res)
					res=curr;
			}
		}
		if(res==Integer.MAX_VALUE)
		{
			writer.println(-1);
		}
		else
		{
			writer.println(res);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Test {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		Map<Integer, Integer> up = new TreeMap<Integer, Integer>();
		Map<Integer, Integer> down = new TreeMap<Integer, Integer>();
		Set<Integer> colors = new TreeSet<Integer>();
		int n = nextInt();
		for (int i = 0; i < n; i++) {
			int c1 = nextInt();
			int c2 = nextInt();
			colors.add(c1);
			if (up.containsKey(c1)) {
				up.put(c1, up.get(c1) + 1);
			} else {
				up.put(c1, 1);
			}
			if (c2 != c1) {
				colors.add(c2);
				if (down.containsKey(c2)) {
					down.put(c2, down.get(c2) + 1);
				} else {
					down.put(c2, 1);
				}
			}
		}
		int res = Integer.MAX_VALUE;
		int need = (n + 1) / 2;
		for (int i : colors) {
			int gotu = 0;
			int gotd = 0;
			if (up.containsKey(i)) {
				gotu = up.get(i);
			}
			if (down.containsKey(i)) {
				gotd = down.get(i);
			}
			if (gotu + gotd >= need) {
				int curr = need - gotu;
				if (curr < 0)
					curr = 0;
				if (curr < res)
					res = curr;
			}
		}
		if (res == Integer.MAX_VALUE) {
			writer.println(-1);
		} else {
			writer.println(res);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class D {

    private void solve() throws IOException {
        int n = nextInt();
        HashMap<Integer, Integer> H1 = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> H2 = new HashMap<Integer, Integer>();

        int half = n / 2 /*+ ((n % 2 == 0) ? 0 : 1)*/;

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (H2.containsKey(to)) {
                H2.put(to, H2.get(to) + 1);
            } else {
                H2.put(to, 1);
            }
        }

        int min = Integer.MAX_VALUE;
        for (int k : H1.keySet()) {
            boolean isHalf = false;
            int res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            } else {
                Integer s = H2.get(k);
                if (s != null) {
                    int ss = (int) s;
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }
            }
            if (isHalf)
                min = Math.min(min, res);
        }
        for (int k : H2.keySet()) {
            int p = H2.get(k);
            if (p >= half)
                min = Math.min(min, p);
        }
        pl(min == Integer.MAX_VALUE ? -1 : min);
    }

    public static void main(String[] args) {
        new D().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class C_129 {

    private void solve() throws IOException {
        int n = nextInt();
        Hashtable<Integer, Integer> H1 = new Hashtable<Integer, Integer>();
        Hashtable<Integer, Integer> H2 = new Hashtable<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (from != to) {
                if (H2.containsKey(to)) {
                    H2.put(to, H2.get(to) + 1);
                } else {
                    H2.put(to, 1);
                }
            }
        }

        int min = 1000000;
        boolean isHalf = false;
        int res = 0;
        Set<Integer> S1 = H1.keySet();
        Set<Integer> S2 = H2.keySet();

        for (int k : S1) {
            isHalf = false;
            res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            } else {
                if (H2.containsKey(k)) {
                    int ss = H2.get(k);
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }

            }
            if (isHalf)
                min = Math.min(min, res);
        }
        for (int k : S2) {
            int p = H2.get(k);
            if (p >= half)
                min = Math.min(min, half);
        }

        pl(min == 1000000 ? -1 : min);
    }

    public static void main(String[] args) {
        new C_129().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class D {

    private void solve() throws IOException {
        int n = nextInt();
        HashMap<Integer, Integer> H1 = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> H2 = new HashMap<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (from != to) {
                if (H2.containsKey(to)) {
                    H2.put(to, H2.get(to) + 1);
                } else {
                    H2.put(to, 1);
                }
            }
        }

        int min = Integer.MAX_VALUE;
        for (int k : H1.keySet()) {
            boolean isHalf = false;
            int res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            }
            else {
                Integer s = H2.get(k);
                if (s != null) {
                    int ss = (int) s;
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }
            }
            if (isHalf) min = Math.min(min, res);
        }
        for (int k : H2.keySet()) {
            int p = H2.get(k);
            if (p >= half) min = Math.min(min, half);
        }
        pl(min == Integer.MAX_VALUE ? -1 : min);
    }

    public static void main(String[] args) {
        new D().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class D {

    private void solve() throws IOException {
        int n = nextInt();
        HashMap<Integer, Integer> H1 = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> H2 = new HashMap<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (from != to) {
                if (H2.containsKey(to)) {
                    H2.put(to, H2.get(to) + 1);
                } else {
                    H2.put(to, 1);
                }
            }
        }

        int min = Integer.MAX_VALUE;
        for (int k : H1.keySet()) {
            boolean isHalf = false;
            int res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            }
            else {
                Integer s = H2.get(k);
                if (s != null) {
                    int ss = (int) s;
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }
            }
            if (isHalf) min = Math.min(min, res);
        }
        for (int k : H2.keySet()) {
            int p = H2.get(k);
            if (p >= half) min = Math.min(min, p);
        }
        pl(min == Integer.MAX_VALUE ? -1 : min);
    }

    public static void main(String[] args) {
        new D().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class C_129 {

    private void solve() throws IOException {
        int n = nextInt();
        Hashtable<Integer, Integer> H1 = new Hashtable<Integer, Integer>();
        Hashtable<Integer, Integer> H2 = new Hashtable<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (from != to) {
                if (H2.containsKey(to)) {
                    H2.put(to, H2.get(to) + 1);
                } else {
                    H2.put(to, 1);
                }
            }
        }

        int min = 1000000;
        boolean isHalf = false;
        int res = 0;
        Set<Integer> S1 = H1.keySet();
        Set<Integer> S2 = H2.keySet();

        for (int k : S1) {
            isHalf = false;
            res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            } else {
                if (H2.contains(k)) {
                    int ss = H2.get(k);
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }

            }
            if (isHalf)
                min = Math.min(min, res);
        }
        for (int k : S2) {
            int p = H2.get(k);
            if (p >= half)
                min = Math.min(min, p);
        }

        pl(min == 1000000 ? -1 : min);
    }

    public static void main(String[] args) {
        new C_129().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class D {

    private void solve() throws IOException {
        int n = nextInt();
        HashMap<Integer, Integer> H1 = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> H2 = new HashMap<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (H2.containsKey(to)) {
                H2.put(to, H2.get(to) + 1);
            } else {
                H2.put(to, 1);
            }
        }

        int min = Integer.MAX_VALUE;
        for (int k : H1.keySet()) {
            boolean isHalf = false;
            int res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            }
            else {
                Integer s = H2.get(k);
                if (s != null) {
                    int ss = (int) s;
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }
            }
            if (isHalf) min = Math.min(min, res);
        }
        for (int k : H2.keySet()) {
            int p = H2.get(k);
            if (p >= half) min = Math.min(min, p);
        }
        pl(min == Integer.MAX_VALUE ? -1 : min);
    }

    public static void main(String[] args) {
        new D().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class D {

    private void solve() throws IOException {
        int n = nextInt();
        HashMap<Integer, Integer> H1 = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> H2 = new HashMap<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (H2.containsKey(to)) {
                H2.put(to, H2.get(to) + 1);
            } else {
                H2.put(to, 1);
            }
        }

        int min = Integer.MAX_VALUE;
        for (int k : H1.keySet()) {
            boolean isHalf = false;
            int res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            }
            else {
                Integer s = H2.get(k);
                if (s != null) {
                    int ss = (int) s;
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }
            }
            if (isHalf) min = Math.min(min, res);
        }
        for (int k : H2.keySet()) {
            int p = H2.get(k);
            if (p >= half) min = Math.min(min, p);
        }
        pl(min);
    }

    public static void main(String[] args) {
        new D().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class C_129 {

    private void solve() throws IOException {
        int n = nextInt();
        Hashtable<Integer, Integer> H1 = new Hashtable<Integer, Integer>();
        Hashtable<Integer, Integer> H2 = new Hashtable<Integer, Integer>();

        int half = n / 2 + ((n % 2 == 0) ? 0 : 1);

        for (int i = 0; i < n; i++) {
            int from = nextInt();
            int to = nextInt();

            if (H1.containsKey(from)) {
                H1.put(from, H1.get(from) + 1);
            } else {
                H1.put(from, 1);
            }

            if (from != to) {
                if (H2.containsKey(to)) {
                    H2.put(to, H2.get(to) + 1);
                } else {
                    H2.put(to, 1);
                }
            }
        }

        int min = 1000000;
        boolean isHalf = false;
        int res = 0;
        Set<Integer> S1 = H1.keySet();
        Set<Integer> S2 = H2.keySet();

        for (int k : S1) {
            isHalf = false;
            res = 0;
            int v = H1.get(k);
            if (v >= half) {
                isHalf = true;
            } else {
                if (H2.containsKey(k)) {
                    int ss = H2.get(k);
                    if (ss >= (half - v)) {
                        res += (half - v);
                        isHalf = true;
                    }
                }

            }
            if (isHalf)
                min = Math.min(min, res);
        }
        for (int k : S2) {
            int p = H2.get(k);
            if (p >= half)
                min = Math.min(min, p);
        }

        pl(min == 1000000 ? -1 : min);
    }

    public static void main(String[] args) {
        new C_129().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    void p(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.flush();
            writer.print(objects[i]);
            writer.flush();
        }
    }

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeMap;

public class D {

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		TreeMap<Integer, Integer> front = new TreeMap<Integer, Integer>();
		TreeMap<Integer, Integer> back = new TreeMap<Integer, Integer>();
		TreeMap<Integer, Integer> tot = new TreeMap<Integer, Integer>();
		LinkedList<Integer> cand = new LinkedList<Integer>();
		int n2 = (n / 2) + (n & 1);
		for (int i = 0; i < n; i++)
		{
			int a = scan.nextInt();
			int b = scan.nextInt();
			Integer t = front.get(a);
			if (t == null)
				t = 0;
			front.put(a, t + 1);
			if (b != a)
			{
				t = back.get(b);
				if (t == null)
					t = 0;
				back.put(b, t + 1);
			}
			if (b != a)
			{
				t = tot.get(b);
				if (t == null)
					t = 0;
				int s = t + 1;
				if (s >= n2)
					cand.add(b);
				tot.put(b, s);
			}
			t = tot.get(a);
			if (t == null)
				t = 0;
			int s = t + 1;
			if (s >= n2)
				cand.add(a);
			tot.put(a, s);
		}

		int min = Integer.MAX_VALUE;
		for (int a : cand)
		{
			Integer f = front.get(a);
			Integer b = back.get(a);
			if (b == null)
				b = 0;
			if (f == null)
				f = 0;
			if (b >= n2 - f)
				min = Math.min(min, Math.max(0, n2 - f));
		}
		if (min == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(min);
	}

}


import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class D {

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		HashMap<Integer, Integer> front = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> back = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> tot = new HashMap<Integer, Integer>();
		LinkedList<Integer> cand = new LinkedList<Integer>();
		int n2 = (n/2)+ (n&1);
		for (int i = 0; i < n; i++)
		{
			int a = scan.nextInt();
			int b = scan.nextInt();
			Integer t = front.get(a);
			if (t == null)
			{
				front.put(a, 1);
			} else
			{
				front.put(a, t + 1);
			}
			if (b != a)
			{
				t = back.get(b);
				if (t == null)
					t = 0;
				back.put(b, t + 1);
			}
			if (b != a)
			{
				t = tot.get(b);
				if (t == null)
				{
					tot.put(b, 1);
				} else
				{
					int s = t + 1;
					if (s >= n2)
						cand.add(b);
					tot.put(b, s);
				}
			}
			t = tot.get(a);
			if (t == null)
			{
				tot.put(a, 1);
			} else
			{
				int s = t + 1;
				if (s >= n2)
					cand.add(a);
				tot.put(a, s);
			}
		}

		int min = Integer.MAX_VALUE;
		for (int a : cand)
		{
			Integer f = front.get(a);
			Integer b = back.get(a);
			if (b == null)
				b = 0;
			if (f != null && b >= n2 - f)
				min = Math.min(min, Math.max(0 , n2 - f));
		}
		if (min == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(min);
	}

}


import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class D {

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		HashMap<Integer, Integer> front = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> back = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> tot = new HashMap<Integer, Integer>();
		LinkedList<Integer> cand = new LinkedList<Integer>();
		int n2 = (n / 2) + (n & 1);
		for (int i = 0; i < n; i++)
		{
			int a = scan.nextInt();
			int b = scan.nextInt();
			Integer t = front.get(a);
			if (t == null)
				t = 0;
			front.put(a, t + 1);
			if (b != a)
			{
				t = back.get(b);
				if (t == null)
					t = 0;
				back.put(b, t + 1);
			}
			if (b != a)
			{
				t = tot.get(b);
				if (t == null)
					t = 0;
				int s = t + 1;
				if (s >= n2)
					cand.add(b);
				tot.put(b, s);
			}
			t = tot.get(a);
			if (t == null)
				t = 0;
			int s = t + 1;
			if (s >= n2)
				cand.add(a);
			tot.put(a, s);
		}

		int min = Integer.MAX_VALUE;
		for (int a : cand)
		{
			Integer f = front.get(a);
			Integer b = back.get(a);
			if (b == null)
				b = 0;
			if (f == null)
				f = 0;
			if (b >= n2 - f)
				min = Math.min(min, Math.max(0, n2 - f));
		}
		if (min == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(min);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class D {
    public static void main(String[] args) throws IOException {
         InputReader in = new InputReader();
         int n = in.nextInt();
//      int n = 100000;
        HashSet<Integer> set = new HashSet<Integer>(n * 2 + 10);
        TreeMap<Integer, colors> map = new TreeMap<Integer, colors>();
        ArrayList<Integer> all = new ArrayList<Integer>(n * 2 + 100);

        for (int i = 0; i < n; i++) {
             in.hasNext();
             int c1 = in.nextInt(), c2 = in.nextInt();
//          int c1 = (int) (Math.random() * 1000000000), c2 = (int) (Math
//                  .random() * 1000000000);
            if (set.contains(c1)) {
                map.get(c1).currSide++;
            } else {
                colors c = new colors(c1);
                c.currSide++;
                map.put(c1, c);
                all.add(c1);
                set.add(c1);
            }

            if (set.contains(c2)) {
                if (c1 != c2)
                    map.get(c2).OtherSide++;
            } else {
                colors c = new colors(c2);
                c.OtherSide++;
                map.put(c2, c);
                all.add(c2);
                set.add(c2);
            }
        }

        int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

        for (Map.Entry<Integer, colors> entry : map.entrySet()) {
            colors c = entry.getValue();
            if (c.currSide >= min) {
                System.out.println(0);
                System.exit(0);
            }
            if (c.currSide + c.OtherSide >= min)
                res = Math.min(res, min - c.currSide);
        }

        if (res == 9999999)
            System.out.println(-1);
        else
            System.out.println(res);
    }

    static class colors {
        int c, currSide, OtherSide;

        public colors(int C) {
            c = C;
        }
    }

    static class InputReader {
        BufferedReader buff;
        StringTokenizer tok;
        String cur;

        public InputReader() throws IOException {
            buff = new BufferedReader(new InputStreamReader(System.in));
            tok = new StringTokenizer(cur = buff.readLine());
        }

        public boolean hasNext() throws IOException {
            if (!tok.hasMoreElements()) {
                cur = buff.readLine();
                if (cur == null)
                    return false;
                tok = new StringTokenizer(cur);
            }
            return true;
        }

        public String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(cur = buff.readLine());

            return tok.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class D {
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader();
		int n = in.nextInt();

		HashSet<Integer> set = new HashSet<Integer>(n + 10);
		HashMap<Integer, colors> map = new HashMap<Integer, colors>(n);
		ArrayList<Integer> all = new ArrayList<Integer>(n * 2 + 100);

		for (int i = 0; i < n; i++) {
			in.hasNext();
			int c1 = in.nextInt(), c2 = in.nextInt();
			if (set.contains(c1)) {
				map.get(c1).currSide++;
			} else {
				colors c = new colors(c1);
				c.currSide++;
				map.put(c1, c);
				all.add(c1);
				set.add(c1);
			}

			if (set.contains(c2)) {
				if (c1 != c2)
					map.get(c2).OtherSide++;
			} else {
				colors c = new colors(c2);
				c.OtherSide++;
				map.put(c2, c);
				all.add(c2);
				set.add(c2);
			}
		}

		int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

		for (int i = 0; i < all.size(); i++) {
			colors c = map.get(all.get(i));
			if (c.currSide >= min) {
				System.out.println(0);
				System.exit(0);
			}
			if (c.currSide + c.OtherSide >= min)
				res = Math.min(res, c.OtherSide);

		}
		if (res == 9999999)
			System.out.println(-1);
		else
			System.out.println(res);

	}

	static class colors {
		int c, currSide, OtherSide;

		public colors(int C) {
			c = C;
		}
	}

	static class InputReader {
		BufferedReader buff;
		StringTokenizer tok;
		String cur;

		public InputReader() throws IOException {
			buff = new BufferedReader(new InputStreamReader(System.in));
			tok = new StringTokenizer(cur = buff.readLine());
		}

		public boolean hasNext() throws IOException {
			if (!tok.hasMoreElements()) {
				cur = buff.readLine();
				if (cur == null)
					return false;
				tok = new StringTokenizer(cur);
			}
			return true;
		}

		public String next() throws IOException {
			while (!tok.hasMoreElements())
				tok = new StringTokenizer(cur = buff.readLine());

			return tok.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class D {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();
        HashMap<Integer, colors> map = new HashMap<Integer, colors>(
                n * 2 + 1000);

        for (int i = 0; i < n; i++) {
            in.hasNext();
            int c1 = in.nextInt(), c2 = in.nextInt();
            colors c;
            if ((c = map.get(c1)) != null) {
                c.currSide++;
            } else {
                c = new colors(c1);
                c.currSide++;
                map.put(c1, c);
            }

            if ((c = map.get(c2)) != null) {
                if (c1 != c2)
                    c.OtherSide++;
            } else {
                c = new colors(c2);
                c.OtherSide++;
                map.put(c2, c);
            }
        }

        int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

        for (Map.Entry<Integer, colors> entry : map.entrySet()) {
            colors c = entry.getValue();
            if (c.currSide >= min) {
                System.out.println(0);
                System.exit(0);
            }
            if (c.currSide + c.OtherSide >= min)
                res = Math.min(res, min - c.currSide);
        }

        if (res == 9999999)
            System.out.println(-1);
        else
            System.out.println(res);
    }

    static class colors {
        int c, currSide, OtherSide;

        public colors(int C) {
            c = C;
        }
    }

    static class InputReader {
        BufferedReader buff;
        StringTokenizer tok;
        String cur;

        public InputReader() throws IOException {
            buff = new BufferedReader(new InputStreamReader(System.in));
            tok = new StringTokenizer(cur = buff.readLine());
        }

        public boolean hasNext() throws IOException {
            if (!tok.hasMoreElements()) {
                cur = buff.readLine();
                if (cur == null)
                    return false;
                tok = new StringTokenizer(cur);
            }
            return true;
        }

        public String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(cur = buff.readLine());

            return tok.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class D {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();
        // int n = 100000;
        TreeMap<Integer, colors> map = new TreeMap<Integer, colors>();

        for (int i = 0; i < n; i++) {
            in.hasNext();
            int c1 = in.nextInt(), c2 = in.nextInt();
            // int c1 = (int) (Math.random() * 1000000000), c2 = (int) (Math
            // .random() * 1000000000);
            colors c;
            if ((c = map.get(c1)) != null) {
                c.currSide++;
            } else {
                c = new colors(c1);
                c.currSide++;
                map.put(c1, c);
            }

            if ((c = map.get(c2)) != null) {
                if (c1 != c2)
                    c.OtherSide++;
            } else {
                c = new colors(c2);
                c.OtherSide++;
                map.put(c2, c);
            }
        }

        int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

        for (Map.Entry<Integer, colors> entry : map.entrySet()) {
            colors c = entry.getValue();
            if (c.currSide >= min) {
                System.out.println(0);
                System.exit(0);
            }
            if (c.currSide + c.OtherSide >= min)
                res = Math.min(res, min - c.currSide);
        }

        if (res == 9999999)
            System.out.println(-1);
        else
            System.out.println(res);
    }

    static class colors {
        int c, currSide, OtherSide;

        public colors(int C) {
            c = C;
        }
    }

    static class InputReader {
        BufferedReader buff;
        StringTokenizer tok;
        String cur;

        public InputReader() throws IOException {
            buff = new BufferedReader(new InputStreamReader(System.in));
            tok = new StringTokenizer(cur = buff.readLine());
        }

        public boolean hasNext() throws IOException {
            if (!tok.hasMoreElements()) {
                cur = buff.readLine();
                if (cur == null)
                    return false;
                tok = new StringTokenizer(cur);
            }
            return true;
        }

        public String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(cur = buff.readLine());

            return tok.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;

public class D {
    public static void main(String[] args) throws IOException {
         InputReader in = new InputReader();
         int n = in.nextInt();
//      int n = 100000;
        HashSet<Integer> set = new HashSet<Integer>(n * 2 + 10);
        HashMap<Integer, colors> map = new HashMap<Integer, colors>(n*2+1000);
        ArrayList<Integer> all = new ArrayList<Integer>(n * 2 + 100);

        for (int i = 0; i < n; i++) {
             in.hasNext();
             int c1 = in.nextInt(), c2 = in.nextInt();
//          int c1 = (int) (Math.random() * 1000000000), c2 = (int) (Math
//                  .random() * 1000000000);
            if (set.contains(c1)) {
                map.get(c1).currSide++;
            } else {
                colors c = new colors(c1);
                c.currSide++;
                map.put(c1, c);
                all.add(c1);
                set.add(c1);
            }

            if (set.contains(c2)) {
                if (c1 != c2)
                    map.get(c2).OtherSide++;
            } else {
                colors c = new colors(c2);
                c.OtherSide++;
                map.put(c2, c);
                all.add(c2);
                set.add(c2);
            }
        }

        int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

        for (Map.Entry<Integer, colors> entry : map.entrySet()) {
            colors c = entry.getValue();
            if (c.currSide >= min) {
                System.out.println(0);
                System.exit(0);
            }
            if (c.currSide + c.OtherSide >= min)
                res = Math.min(res, min - c.currSide);
        }

        if (res == 9999999)
            System.out.println(-1);
        else
            System.out.println(res);

    }

    static class colors {
        int c, currSide, OtherSide;

        public colors(int C) {
            c = C;
        }
    }

    static class InputReader {
        BufferedReader buff;
        StringTokenizer tok;
        String cur;

        public InputReader() throws IOException {
            buff = new BufferedReader(new InputStreamReader(System.in));
            tok = new StringTokenizer(cur = buff.readLine());
        }

        public boolean hasNext() throws IOException {
            if (!tok.hasMoreElements()) {
                cur = buff.readLine();
                if (cur == null)
                    return false;
                tok = new StringTokenizer(cur);
            }
            return true;
        }

        public String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(cur = buff.readLine());

            return tok.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class D {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();

        HashMap<Integer, colors> map = new HashMap<Integer, colors>(n);
        ArrayList<Integer> all = new ArrayList<Integer>(n * 2 + 100);

        for (int i = 0; i < n; i++) {
            in.hasNext();
            int c1 = in.nextInt(), c2 = in.nextInt();
            colors c;
            if ((c = map.get(c1)) != null) {
                c.currSide++;
            } else {
                c = new colors(c1);
                c.currSide++;
                map.put(c1, c);
                all.add(c1);
            }

            if ((c = map.get(c2)) != null) {
                if (c1 != c2)
                    map.get(c2).OtherSide++;
            } else {
                c = new colors(c2);
                c.OtherSide++;
                map.put(c2, c);
                all.add(c2);
            }
        }

        int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

        for (int i = 0; i < all.size(); i++) {
            colors c = map.get(all.get(i));
            if (c.currSide >= min) {
                System.out.println(0);
                System.exit(0);
            }
            if (c.currSide + c.OtherSide >= min)
                res = Math.min(res, min - c.currSide);

        }
        if (res == 9999999)
            System.out.println(-1);
        else
            System.out.println(res);

    }

    static class colors {
        int c, currSide, OtherSide;

        public colors(int C) {
            c = C;
        }
    }

    static class InputReader {
        BufferedReader buff;
        StringTokenizer tok;
        String cur;

        public InputReader() throws IOException {
            buff = new BufferedReader(new InputStreamReader(System.in));
            tok = new StringTokenizer(cur = buff.readLine());
        }

        public boolean hasNext() throws IOException {
            if (!tok.hasMoreElements()) {
                cur = buff.readLine();
                if (cur == null)
                    return false;
                tok = new StringTokenizer(cur);
            }
            return true;
        }

        public String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(cur = buff.readLine());

            return tok.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class D {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();

        HashSet<Integer> set = new HashSet<Integer>(n + 10);
        HashMap<Integer, colors> map = new HashMap<Integer, colors>(n);
        ArrayList<Integer> all = new ArrayList<Integer>(n * 2 + 100);

        for (int i = 0; i < n; i++) {
            in.hasNext();
            int c1 = in.nextInt(), c2 = in.nextInt();
            if (set.contains(c1)) {
                map.get(c1).currSide++;
            } else {
                colors c = new colors(c1);
                c.currSide++;
                map.put(c1, c);
                all.add(c1);
                set.add(c1);
            }

            if (set.contains(c2)) {
                if (c1 != c2)
                    map.get(c2).OtherSide++;
            } else {
                colors c = new colors(c2);
                c.OtherSide++;
                map.put(c2, c);
                all.add(c2);
                set.add(c2);
            }
        }

        int res = 9999999, min = n / 2 + (n % 2 == 0 ? 0 : 1);

        for (int i = 0; i < all.size(); i++) {
            colors c = map.get(all.get(i));
            if (c.currSide >= min) {
                System.out.println(0);
                System.exit(0);
            }
            if (c.currSide + c.OtherSide >= min)
                res = Math.min(res, min-c.currSide);

        }
        if (res == 9999999)
            System.out.println(-1);
        else
            System.out.println(res);

    }

    static class colors {
        int c, currSide, OtherSide;

        public colors(int C) {
            c = C;
        }
    }

    static class InputReader {
        BufferedReader buff;
        StringTokenizer tok;
        String cur;

        public InputReader() throws IOException {
            buff = new BufferedReader(new InputStreamReader(System.in));
            tok = new StringTokenizer(cur = buff.readLine());
        }

        public boolean hasNext() throws IOException {
            if (!tok.hasMoreElements()) {
                cur = buff.readLine();
                if (cur == null)
                    return false;
                tok = new StringTokenizer(cur);
            }
            return true;
        }

        public String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(cur = buff.readLine());

            return tok.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }

}