/**
 *      author : azhar556
 *      12 September 2018   2:45 AM (+7)
**/

#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()

using namespace std;

typedef double db;
typedef long long i64;

const int MAX = 1e9 + 7;
const db PI = acos(-1.0);

bool rev(pair<int, int> a, pair<int, int> b) {return a > b;}

void solve()
{
	int n;
	cin >> n;

	vector<pair<int, int>> fr;
	vector<int> bk, uniqfr, uniqbk;
	map<int, int> rep;
	for (int a = 0; a < n; a++)
	{
		int x, y;
		cin >> x >> y;

		if (count(all(bk), y) == 0)
			uniqbk.pb(y);

		if (x != y)
			bk.pb(y);

		rep[x]++;
		if (count(all(uniqfr), x) == 0)
		{
			fr.pb(make_pair(x, 0));
			uniqfr.pb(x);
		}
	}

	// for (int a = 0; a < (int)bk.size(); a++)
		// cerr << bk[a] << ' ';

	for (int a = 0; a < (int)fr.size(); a++)
	{
		fr[a].second = rep[fr[a].first];
		swap(fr[a].first, fr[a].second);
	}

	sort(all(fr), rev);

	int Min = INT_MAX, val = INT_MAX;
	for (int a = 0; a < (int)fr.size(); a++)
	{
		if (fr[a].first >= ceil(1.0 * n / 2))
		{
			cout << 0;
			return;
		}
		else
		{
			if (count(all(bk), fr[a].second) + fr[a].first >= ceil(1.0 * n / 2))
				val = ceil(1.0 * n / 2) - fr[a].first;

			Min = min(Min, val);
		}
	}

	if (Min == INT_MAX)
		for (int a = 0; a < (int)uniqbk.size(); a++)
			if (count(all(bk), uniqbk[a]) >= ceil(1.0 * n / 2))
			{
				Min = ceil(1.0 * n / 2);
				break;
			}

	if (Min == INT_MAX)
		cout << -1;
	else
		cout << Min;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	solve();

	cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


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

int main()
{   int i,flag=0,temp;
    map<int,int>ft;
     map<int,int>bk;
    long long int n,a,b;
    long long int funny;
    int mini = INT_MAX;
    cin>>n;
    if(n%2==0)
    funny=(n/2);
    else
        funny=(n+1)/2;
    for(i=0 ;i<n ;i++){
        cin>>a>>b;
        if (a==b){
            ft[a]++;

        }
    else{
        ft[a]++;
        bk[b]++;}
        if (ft[a]>=funny){
           mini=0;
           flag=1;
        }
    }
    if (flag==1){
        cout<<mini<<endl;
    }
    else{
    for (map<int, int>::iterator it = ft.begin() ; it != ft.end(); it++){

		if(funny<=((it->second)+(bk[it->first]))){

            temp =funny-(it->second);
            if (temp<mini){
                mini=temp;
            }
		}

    }
    cout << mini<< endl;
   }

    return 0;
}


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

int main()
{   int i,flag=0;
    map<int,int>ft;
     map<int,int>bk;
    long long int n,a,b;
    long long int funny,temp;
    long long  mini = INT_MAX;

    cin>>n;
    if(n%2==0)
    funny=(n/2);
    else
        funny=(n+1)/2;
    for(i=0 ;i<n ;i++){
        cin>>a>>b;
        if (a==b){
            ft[a]++;

        }
    else{
        ft[a]++;
        bk[b]++;}
        if (ft[a]>=funny){
           mini=0;
           flag=1;
        }
        if (ft[b]>=funny&&mini!=0){
            if(ft[b]<mini){
                mini=ft[b];
            }
        }
    }
    //cout<<" funny " <<funny<<endl;
    if (flag==1){
        cout<<mini<<endl;
    }
    else{
    for (map<int, int>::iterator it = ft.begin() ; it != ft.end(); it++){
        //cout<<" kagibunshinnojutsu " <<(it->second)+(bk[it->first])<<endl;
		if(funny<=((it->second)+(bk[it->first]))){

            temp =funny-(it->second);
            if (temp<mini){
                mini=temp;
            }
		}

    }
    if(mini==INT_MAX)
        mini=-1;

    cout << mini<< endl;
   }

    return 0;
}


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

int main()
{   int i,flag=0;
    map<int,int>ft;
     map<int,int>bk;
    long long int n,a,b;
    long long int funny,temp;
    long long  mini = INT_MAX;

    cin>>n;
    if(n%2==0)
    funny=(n/2);
    else
        funny=(n+1)/2;
    for(i=0 ;i<n ;i++){
        cin>>a>>b;
        if (a==b){
            ft[a]++;

        }
    else{
        ft[a]++;
        bk[b]++;}
        if (ft[a]>=funny){
           mini=0;
           flag=1;
        }
    }
    if (flag==1){
        cout<<mini<<endl;
    }
    else{
    for (map<int, int>::iterator it = ft.begin() ; it != ft.end(); it++){

		if(funny<=((it->second)+(bk[it->first]))){

            temp =funny-(it->second);
            if (temp<mini){
                mini=temp;
            }
		}

    }
    if(mini==INT_MAX)
        mini=-1;

    cout << mini<< endl;
   }

    return 0;
}


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

int main()
{   int i,flag=0,temp;
    map<int,int>ft;
     map<int,int>bk;
    long long int n,a,b;
    long long int funny;
    int mini = INT_MAX;
    cin>>n;
    if(n%2==0)
    funny=(n/2);
    else
        funny=(n+1)/2;
    for(i=0 ;i<n ;i++){
        cin>>a>>b;
        if (a==b){
            ft[a]++;
            continue;
        }
        ft[a]++;
        bk[b]++;
        if (ft[a]>=funny){
           mini=0;
           flag=1;
        }
    }
    if (flag==1){
        cout<<mini<<endl;
    }
    else{
    for (map<int, int>::iterator it = ft.begin() ; it != ft.end(); it++){

		if(funny<=((it->second)+(bk[it->first]))){

            temp =funny-(it->second);
            if (temp<mini){
                mini=temp;
            }
		}

    }
    cout << mini<< endl;
   }

    return 0;
}


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

int main()
{   int i,flag=0,temp;
    map<int,int>ft;
     map<int,int>bk;
    long long int n,a,b;
    long long int funny;
    int mini = INT_MAX;
    cin>>n;
    if(n%2==0)
    funny=(n/2);
    else
        funny=(n+1)/2;
    for(i=0 ;i<n ;i++){
        cin>>a>>b;
        if (a==b){
            ft[a]++;

        }
    else{
        ft[a]++;
        bk[b]++;}
        if (ft[a]>=funny){
           mini=0;
           flag=1;
        }
    }
    if (flag==1){
        cout<<mini<<endl;
    }
    else{
    for (map<int, int>::iterator it = ft.begin() ; it != ft.end(); it++){

		if(funny<=((it->second)+(bk[it->first]))){

            temp =funny-(it->second);
            if (temp<mini){
                mini=temp;
            }
		}

    }
    if(mini==INT_MAX)
        mini=-1;

    cout << mini<< endl;
   }

    return 0;
}


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

int main()
{   int i,flag=0,temp;
    map<int,int>ft;
     map<int,int>bk;
    long long int n,a,b;
    long long int funny;
    long long  mini = INT_MAX;

    cin>>n;
    if(n%2==0)
    funny=(n/2);
    else
        funny=(n+1)/2;
    for(i=0 ;i<n ;i++){
        cin>>a>>b;
        if (a==b){
            ft[a]++;

        }
    else{
        ft[a]++;
        bk[b]++;}
        if (ft[a]>=funny){
           mini=0;
           flag=1;
        }
    }
    if (flag==1){
        cout<<mini<<endl;
    }
    else{
    for (map<int, int>::iterator it = ft.begin() ; it != ft.end(); it++){

		if(funny<=((it->second)+(bk[it->first]))){

            temp =funny-(it->second);
            if (temp<mini){
                mini=temp;
            }
		}

    }
    if(mini==INT_MAX)
        mini=-1;

    cout << mini<< endl;
   }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define  sz(x)      x.size()
#define  nl       printf("\n")
#define  lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define  lpmap(x,y)  for(x=y.begin();x!=y.end();x++)
#define  Sort(v) sort(v.begin(),v.end())
#define  pi (2*acos(0))
#define  fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  VI vector<int>
#define  SI set<int>
#define  NL printf("\n")
#define  VL vector<ll>
#define  MP map<int,int>
#define  SL set<ll>
#define  SORT(c)  sort(c.begin(),c.end())
#define  len(s)   s.length()
#define  sz(s)    s.size()
#define mk() make_pair()
#define MAX (1ll<<62)
#define MIN -(1ll<<62)
#define mpii  map<int,int>
#define mpll  map<ll,ll>
#define mpli  map<ll,int>
#define mpsi map<string,int>
#define fast ios_base::sync_with_stdio(false);
#define opt cin.tie(NULL);
ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
//template<class T> T inpwr(T b ,T e ){ll ret=b; for(ll i=1;i<=e-1;i++)ret/=2ll; return ret;}

int n,m,x,y,u,v;

map<int, int> mp,mp1,mp2;
int ans;
int ar[100005],br[100005];
map<int , int> :: iterator it;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(n);
    int need=(n%2==0)?n/2:n/2+1;
   // op(need);
    lp(i,n)
   {
       sc2(a,b);
       mp[a]++;
       mp1[b]++;
       ar[i]=a;
       br[i]=b;
       if(a==b)
        mp2[a]++;
   }
int mn=imn;
   for(i=0;i<n;i++)
   {
       int lt=ar[i];
       int rt=br[i];
       int now= mp[lt]+mp1[lt]-mp2[lt];
      if(mp[lt]>=need)
       {
           mn=0;
           break;
       }
       if(now>=need)
       {
           int ans=need-mp[lt];
           mn=min(mn,ans);
       }
    int now1=mp[rt]+mp1[rt]-mp2[rt];
    if(now1>=need)
    {
        mn=min(need,mn);
    }

   }
if(mn==imn)
    cout<<-1<<endl;
else
    pf1(mn);

    return 0;

}

/*

10
9 1000000000
47 74
47474 75785445
8798878 458445
1 2
888888888 777777777
99999999 1000000000
9999999 1000000000
999999 1000000000
99999 1000000000

*/


#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define  sz(x)      x.size()
#define  nl       printf("\n")
#define  lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define  lpmap(x,y)  for(x=y.begin();x!=y.end();x++)
#define  Sort(v) sort(v.begin(),v.end())
#define  pi (2*acos(0))
#define  fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  VI vector<int>
#define  SI set<int>
#define  NL printf("\n")
#define  VL vector<ll>
#define  MP map<int,int>
#define  SL set<ll>
#define  SORT(c)  sort(c.begin(),c.end())
#define  len(s)   s.length()
#define  sz(s)    s.size()
#define mk() make_pair()
#define MAX (1ll<<62)
#define MIN -(1ll<<62)
#define mpii  map<int,int>
#define mpll  map<ll,ll>
#define mpli  map<ll,int>
#define mpsi map<string,int>
#define fast ios_base::sync_with_stdio(false);
#define opt cin.tie(NULL);
ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
//template<class T> T inpwr(T b ,T e ){ll ret=b; for(ll i=1;i<=e-1;i++)ret/=2ll; return ret;}

int n,m,x,y,u,v;

map<int, int> mp,mp1,mp2;
int ans;
int ar[100005],br[100005];
map<int , int> :: iterator it;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(n);
    int need=(n%2==0)?n/2:n/2+1;
   // op(need);
    lp(i,n)
   {
       sc2(a,b);
       mp[a]++;
       mp1[b]++;
       ar[i]=a;
       br[i]=b;
       if(a==b)
        mp2[a]++;
   }
int mn=imn;
   for(it=mp.begin();it!=mp.end();it++)
   {
       int now=it->ff;
       int freq= mp[now];
       if(freq>=need)
        {
            mn=0;
            break;
        }
       freq=mp[now]+mp1[now];
       freq-=mp2[now];
       if(freq>=need)
       {
           mn=min(mn,need-mp[now]);
       }

   }
   if(mn==imn)
    cout<<-1<<endl;
   op(mn);

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define  sz(x)      x.size()
#define  nl       printf("\n")
#define  lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define  lpmap(x,y)  for(x=y.begin();x!=y.end();x++)
#define  Sort(v) sort(v.begin(),v.end())
#define  pi (2*acos(0))
#define  fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  VI vector<int>
#define  SI set<int>
#define  NL printf("\n")
#define  VL vector<ll>
#define  MP map<int,int>
#define  SL set<ll>
#define  SORT(c)  sort(c.begin(),c.end())
#define  len(s)   s.length()
#define  sz(s)    s.size()
#define mk() make_pair()
#define MAX (1ll<<62)
#define MIN -(1ll<<62)
#define mpii  map<int,int>
#define mpll  map<ll,ll>
#define mpli  map<ll,int>
#define mpsi map<string,int>
#define fast ios_base::sync_with_stdio(false);
#define opt cin.tie(NULL);
ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
//template<class T> T inpwr(T b ,T e ){ll ret=b; for(ll i=1;i<=e-1;i++)ret/=2ll; return ret;}

int n,m,x,y,u,v;

map<int, int> mp,mp1,mp2;
int ans;
int ar[100005],br[100005];
map<int , int> :: iterator it;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(n);
    int need=(n%2==0)?n/2:n/2+1;
    lp(i,n)
   {
       sc2(a,b);
       mp[a]++;
       mp1[b]++;
       ar[i]=a;
       br[i]=b;
       if(a==b)
        mp2[a]++;
   }
int mn=imn;
   for(it=mp.begin();it!=mp.end();it++)
   {
       int now=it->ff;
       int freq= mp[now];
       if(freq>=need)
        mn=min(0,mn);
       freq=mp[now]+mp1[now];
       freq-=mp2[now];
       if(freq>=need)
       {
           mn=min(mn,need-mp[now]);
       }

   }
   if(mn==imn)
    cout<<-1<<endl;
   op(mn);

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define  mt(a,x,b) memset(a,x,sizeof a)
#define  mem(a) memset(a,0,sizeof a)
#define  lp(i,n)    for(i=0;i<n;i++)
#define  lpp(x,a,b) for(x=a;x<=b;x++)
#define  lpr(x,a,b) for(x=a;x>=b;x--)
#define  pb push_back
#define  prr pair<int,int>
#define  imn INT_MAX
#define  imx INT_MIN
#define  sc scanf
#define  pt(tc)  printf("Case %d: ",tc++)
#define  ptt(tc) printf("Case %d:\n",tc++)
#define  pf printf
#define  op(n) cout<<n<<endl
#define  eps 1.e-9
#define  ff first
#define  ss second
#define  ll long long
#define  wh(t)  while(t--)
#define  ug unsigned
#define  fin  freopen("input.txt","r",stdin)
#define  fout  freopen("output.txt","w",stdout)
#define  sc1(x)      scanf("%d",&x)
#define  sc2(x,y)    scanf("%d %d",&x,&y)
#define  sc3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define  scl1(x)     scanf("%lld",&x)
#define  scl2(x,y)   scanf("%lld %lld",&x,&y)
#define  scl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  scf1(x)     scanf("%lf",&x)
#define  scf2(x,y)   scanf("%lf %lf",&x,&y)
#define  pf1(x)      printf("%d\n",x)
#define  srt(a) a.begin(),a.end()
#define  pfl1(x)     printf("%lld\n",x)
#define  LB(a,x) (lower_bound(srt(a),x)-a.begin())
#define  UB(a,x) (upper_bound(srt(a),x)-a.begin())
#define  op3(x,y,z)   cout<<x<<" "<<y<<" "<<z<<endl;
#define  sz(x)      x.size()
#define  nl       printf("\n")
#define  lpset(x,y)  for(x=y.begin();x!=y.end();x++)
#define  lpmap(x,y)  for(x=y.begin();x!=y.end();x++)
#define  Sort(v) sort(v.begin(),v.end())
#define  pi (2*acos(0))
#define  fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  VI vector<int>
#define  SI set<int>
#define  NL printf("\n")
#define  VL vector<ll>
#define  MP map<int,int>
#define  SL set<ll>
#define  SORT(c)  sort(c.begin(),c.end())
#define  len(s)   s.length()
#define  sz(s)    s.size()
#define mk() make_pair()
#define MAX (1ll<<62)
#define MIN -(1ll<<62)
#define mpii  map<int,int>
#define mpll  map<ll,ll>
#define mpli  map<ll,int>
#define mpsi map<string,int>
#define fast ios_base::sync_with_stdio(false);
#define opt cin.tie(NULL);
ll mod = 1;

#define MX

//int Set(int n,int pos)  { return n = n | 1<<pos;}
//bool check(int n,int pos) { return n & 1<<pos;}
//int Reset(int n, int pos) { return n=n & ~(1<<pos);}
//template<class T> inline T on(T n, T pos){return n | (1<<pos);}
//template <class T> inline T check(T n, T pos){return (bool)  n&(1<<pos);}
//template<class T> inline T gcd(T a, T b){if(b==0)return a ;else return gcd(b,a%b);}
//template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
//template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
//template<class T> inline T lcm(T a, T b) {return a*b/gcd(a,b);}
//template<class T> inline T diff(T x2,T x1, T y2 ,T y1  ){double x ,y; x=((x2-x1)*(x2-x1)); y = ((y2-y1)*(y2-y1));return sqrt(x+y);}
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dxh[]={2,1,-1,-2,-2,-1,1,2};int dyh[]={1,2,2,1,-1,-2,-2,-1};
//int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
//template <class T> inline T bigpow(T p,T e){  ll ret = 1; for(; e > 0; e >>= 1) {if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//int toLlint(string s){long long int sm;stringstream ss(s);ss>>sm;return sm;}
//string toStr(int number) {string Str; ostringstream convert; convert<< number;Str = convert.str();return Str; }
//template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
//template <class T> inline T pwr(T b, T e) {ll ret=1;for(ll i=1;i<=e;i++)ret*=b;return ret;}
//template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));}
//template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));}
//template<class T> T inpwr(T b ,T e ){ll ret=b; for(ll i=1;i<=e-1;i++)ret/=2ll; return ret;}

int n,m,x,y,u,v;

map<int, int> mp,mp1,mp2;
int ans;
int ar[100005],br[100005];
map<int , int> :: iterator it;
int main()
{

    int i,j,t,tc=1,a,b;
    sc1(n);
    int need=(n%2==0)?n/2:n/2+1;
   // op(need);
    lp(i,n)
   {
       sc2(a,b);
       mp[a]++;
       mp1[b]++;
       ar[i]=a;
       br[i]=b;
       if(a==b)
        mp2[a]++;
   }
int mn=imn;
   for(it=mp.begin();it!=mp.end();it++)
   {
       int now=it->ff;
       int freq= mp[now];
       if(freq>=need)
        {
            mn=0;
            break;
        }
       freq=mp[now]+mp1[now];
       freq-=mp2[now];
       if(freq>=need)
       {
           mn=min(mn,need-mp[now]);
       }

   }
   if(mn==imn)
    cout<<-1<<endl;
    else
   op(mn);

    return 0;

}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second;
int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;
    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;

        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<n; i++)
        if(V[i].ff>=half)
        {
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]>=need)
            {
                cout<<need<<"\n";
                return 0;
            }
        }
        puts("-1");
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second,same;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;

    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;
        if(f==s)
        {
            same[f]++;

        }
        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<V.size(); i++)
        if(V[i].ff>=half)
        {
//                            puts("OKKK");
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]-same[V[i].ss]>=need)
            {

                cout<<need<<"\n";
                return 0;
            }
        }
    for(it=second.begin(); it!=second.end(); it++)
        if(it->second>=half)
        {
//puts("OOOOOOOO");
            cout<<half-same[it->first]<<"\n";
            return 0;
        }
//        puts("OKK");
    puts("-1");
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second,same;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;

    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;
        if(f==s)
        {
            same[f]++;

        }
        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<n; i++)
        if(V[i].ff>=half)
        {
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]-same[V[i].ss]>=need)
            {
                cout<<need<<"\n";
                return 0;
            }
        }
    for(it=second.begin(); it!=second.end(); it++)
        if(it->second>=half)
        {

            cout<<half<<"\n";
            return 0;
        }
    puts("-1");
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second,same;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;

    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;
        if(f==s)
        {
            same[f]++;

        }
        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<n; i++)
        if(V[i].ff>=half)
        {
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]-same[V[i].ss]>=need)
            {
                cout<<need<<"\n";
                return 0;
            }
        }
    for(it=second.begin(); it!=second.end(); it++)
        if(it->second>=half)
        {

            cout<<half-same[it->first]<<"\n";
            return 0;
        }
    puts("-1");
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second,same;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;

    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;
        if(f==s)
        {
            same[f]++;

        }
        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<n; i++)
        if(V[i].ff>=half)
        {
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]-same[V[i].ss]>=need)
            {
                cout<<need<<"\n";
                return 0;
            }
        }
    puts("-1");
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second;
int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;
    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;
        if(f==s)
        {
            for(;;);
        }
        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<n; i++)
        if(V[i].ff>=half)
        {
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]>=need)
            {
                cout<<need<<"\n";
                return 0;
            }
        }
    puts("-1");
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
map<int,int>first,second,same;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> >V;

    for(int i=0; i<n; i++)
    {
        int f,s;
        cin>>f>>s;
        if(f==s)
        {
            same[f]++;

        }
        first[f]++;
        second[s]++;
    }
    map<int,int>:: iterator it;
    for(it=first.begin(); it!=first.end(); it++)
    {
        V.PB(MP(it->second,it->first));
    }
    sort(ALL(V));
    reverse(ALL(V));
    int half=(n+1)/2;
    for(int i=0; i<n; i++)
        if(V[i].ff>=half)
        {
            cout<<0<<"\n";
            return 0;
        }
        else
        {
            int need=half-V[i].ff;
            if(second[V[i].ss]-same[V[i].ss]>=need)
            {
                cout<<need<<"\n";
                return 0;
            }
        }
    for(it=second.begin(); it!=second.end(); it++)
        if(it->second>=half)
        {
//puts("OOOOOOOO");
            cout<<half-same[it->first]<<"\n";
            return 0;
        }
    puts("-1");
}


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

int main()
{

    int n;
    map<int,int> mpl, mpr;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {   int l, r;
        scanf("%d%d",&l,&r);
        mpl[l]++;
        if(l!=r)
        mpr[r]++;
    }

    int t;
    int ans = 1e9;
    for(auto x : mpl)
    {
        if(x.second > n/2)
        {
            t = 0;
        }
        else
        {
            if(x.second+mpr[x.first] >= ceil(n/2.0))
            {
                t = ceil(n/2.0) - x.second;
            }
            else
                continue;
        }
        //printf("%d %d\n", x.first, ans);
        ans = min(ans,t);
    }
    if(ans == 1e9)
        {
            for(auto x : mpr)
            {
                if(x.second >= ceil(n/2.0))
                {
                    ans = n/2;
                }
            }
        }
        if(ans == 1e9)
            ans = -1;
    printf("%d\n",ans);
    return 0;
}


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

int main()
{

    int n;
    map<int,int> mpl, mpr;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {   int l, r;
        scanf("%d%d",&l,&r);
        mpl[l]++;
        if(l!=r)
        mpr[r]++;
    }

    int t;
    int ans = 1e9;
    for(auto x : mpl)
    {
        if(x.second > n/2)
        {
            t = 0;
        }
        else
        {
            if(x.second+mpr[x.first] >= ceil(n/2.0))
            {
                t = ceil(n/2.0) - x.second;
            }
            else
                continue;
        }
        //printf("%d %d\n", x.first, ans);
        ans = min(ans,t);
    }
    if(ans == 1e9)
        {
            for(auto x : mpr)
            {
                if(x.second >= ceil(n/2.0))
                {
                    ans = ceil(n/2.0);
                }
            }
        }
        if(ans == 1e9)
            ans = -1;
    printf("%d\n",ans);
    return 0;
}


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

int main()
{

    int n;
    map<int,int> mpl, mpr;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {   int l, r;
        scanf("%d%d",&l,&r);
        mpl[l]++;
        if(l!=r)
        mpr[r]++;
    }

    int t;
    int ans = 1e9;
    for(auto x : mpl)
    {
        if(x.second > n/2)
        {
            t = 0;
        }
        else
        {
            if(x.second+mpr[x.first] >= ceil(n/2.0))
            {
                t = ceil(n/2.0) - x.second;
            }
            else
                continue;
        }
        //printf("%d %d\n", x.first, ans);
        ans = min(ans,t);
    }
    if(ans == 1e9)
        {
            for(auto x : mpr)
            {
                if(x.second >= ceil(n/2.0))
                {
                    ans = ceil(n/2);
                }
            }
        }
        if(ans == 1e9)
            ans = -1;
    printf("%d\n",ans);
    return 0;
}


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

int main()
{

    int n;
    map<int,int> mpl, mpr;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {   int l, r;
        scanf("%d%d",&l,&r);
        mpl[l]++;
        mpr[r]++;
    }

    int t;
    int ans = 1e9;
    for(auto x : mpl)
    {
        if(x.second > n/2)
        {
            t = 0;
        }
        else
        {
            if(x.second+mpr[x.first] >= ceil(n/2.0))
            {
                t = ceil(n/2.0) - x.second;
            }
            else
                continue;
        }
        //printf("%d %d\n", x.first, ans);
        ans = min(ans,t);
    }
    if(ans == 1e9)
        ans = -1;
    printf("%d\n",ans);
    return 0;
}


/*
3
4 7
4 7
7 4
*/
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int q[N],tt;
map<int,int> cnt1,cnt2;
int main(){
	int n;
	scanf("%d",&n);
	int s=n+1>>1;
	for(int i=1;i<=n;i++){
		int	x,y;
		scanf("%d%d",&x,&y);
		cnt1[x]++;
		if(x!=y)cnt1[y]++;
		cnt2[x]++;
		q[++tt]=x;q[++tt]=y;
	}
	int res=0x7f7f7f7f;
	for(int i=1;i<=tt;i++){
		if(cnt1[q[i]]>=s&&cnt2[q[i]]>=s)return puts("0"),0;
		if(cnt1[q[i]]>=s)res=min(res,s-cnt2[q[i]]);
	}
	if(res==0x7f7f7f7f)puts("-1");
	else printf("%d\n",res);
	return 0;
}


/*
3
4 7
4 7
7 4
*/
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+10;
int q[N],tt;
map<int,int> cnt1,cnt2;
int main(){
	int n;
	scanf("%d",&n);
	int s=n+1>>1;
	for(int i=1;i<=n;i++){
		int	x,y;
		scanf("%d%d",&x,&y);
		cnt1[x]++;
		if(x!=y)cnt1[y]++;
		cnt2[x]++;
		q[++tt]=x;q[++tt]=y;
	}
	int res=0x7f7f7f7f;
	for(int i=1;i<=tt;i++){
		if(cnt1[q[i]]>=s&&cnt2[q[i]]>=s)return puts("0"),0;
		if(cnt1[q[i]]>=s)res=min(res,s-cnt2[q[i]]);
	}
	if(res==0x7f7f7f7f)puts("-1");
	else printf("%d\n",res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf_int=1000000000;
const ll int_ll=100000000000000000;
const double pi=3.1415926535898;
#define pb push_back
#define dout if(debug) cout
void prin(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}
void prin(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}

int sum_vec(vector<int>& a)
{
    int s=0;
    for(int i=0;i<a.size();i++)
    {
        s+=a[i];
    }
    return s;
}
int min(int a,int b,int c)
{
    return min(a,min(b,c));
}
ll min(ll a,ll b,ll c)
{
    return min(a,min(b,c));
}
int max(int a,int b,int c)
{
    return max(a,max(b,c));
}
ll max(ll a,ll b,ll c)
{
    return max(a,max(b,c));
}
#define FILE "cinema"
#define debug 0
int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0);
   cout.tie(0);
    //  freopen(FILE".in","r",stdin);
   // freopen(FILE".out","w",stdout);
   int n;
   cin >> n;
   int m=ceil(n/2.0);
   map<int,int> fi,se;
   set<int> a;
   for(int i=0;i<n;i++)
   {
       int x;
       cin >> x;
       int y;
       cin >> y;
       fi[x]++;
       se[y]++;
       a.insert(x);
       a.insert(y);
   }
   int ans=inf_int;
   for(set<int>::iterator it=a.begin();it!=a.end();it++)
   {
       int i=*it;
       if(fi[i]+se[i]>=m)
       {
           ans=min(ans,m-min(fi[i],m));
       }
   }
   cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf_int=1000000000;
const ll int_ll=100000000000000000;
const double pi=3.1415926535898;
#define pb push_back
#define dout if(debug) cout
void prin(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}
void prin(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}

int sum_vec(vector<int>& a)
{
    int s=0;
    for(int i=0;i<a.size();i++)
    {
        s+=a[i];
    }
    return s;
}
int min(int a,int b,int c)
{
    return min(a,min(b,c));
}
ll min(ll a,ll b,ll c)
{
    return min(a,min(b,c));
}
int max(int a,int b,int c)
{
    return max(a,max(b,c));
}
ll max(ll a,ll b,ll c)
{
    return max(a,max(b,c));
}
#define FILE "cinema"
#define debug 0
int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0);
   cout.tie(0);
    //  freopen(FILE".in","r",stdin);
   // freopen(FILE".out","w",stdout);
   int n;
   cin >> n;
   int m=ceil(n/2.0);
   map<int,int> fi,se;
   set<int> a;
   for(int i=0;i<n;i++)
   {
       int x;
       cin >> x;
       int y;
       cin >> y;
       fi[x]++;
       if(x!=y)
       se[y]++;
       a.insert(x);
       a.insert(y);
   }
   int ans=inf_int;
   for(set<int>::iterator it=a.begin();it!=a.end();it++)
   {
       int i=*it;
       if(fi[i]+se[i]>=m)
       {
           ans=min(ans,m-min(fi[i],m));
       }
   }
   if(ans==inf_int)
    cout << -1;
   else
   cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf_int=1000000000;
const ll int_ll=100000000000000000;
const double pi=3.1415926535898;
#define pb push_back
#define dout if(debug) cout
void prin(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}
void prin(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}

int sum_vec(vector<int>& a)
{
    int s=0;
    for(int i=0;i<a.size();i++)
    {
        s+=a[i];
    }
    return s;
}
int min(int a,int b,int c)
{
    return min(a,min(b,c));
}
ll min(ll a,ll b,ll c)
{
    return min(a,min(b,c));
}
int max(int a,int b,int c)
{
    return max(a,max(b,c));
}
ll max(ll a,ll b,ll c)
{
    return max(a,max(b,c));
}
#define FILE "cinema"
#define debug 0
int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0);
   cout.tie(0);
    //  freopen(FILE".in","r",stdin);
   // freopen(FILE".out","w",stdout);
   int n;
   cin >> n;
   int m=ceil(n/2.0);
   map<int,int> fi,se;
   set<int> a;
   for(int i=0;i<n;i++)
   {
       int x;
       cin >> x;
       int y;
       cin >> y;
       fi[x]++;
       se[y]++;
       a.insert(x);
       a.insert(y);
   }
   int ans=inf_int;
   for(set<int>::iterator it=a.begin();it!=a.end();it++)
   {
       int i=*it;
       if(fi[i]+se[i]>=m)
       {
           ans=min(ans,m-min(fi[i],m));
       }
   }
   if(ans==inf_int)
    cout << -1;
   else
   cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf_int=1000000000;
const ll int_ll=100000000000000000;
const double pi=3.1415926535898;
#define pb push_back
#define dout if(debug) cout
void prin(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<int>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}
void prin(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<" ";
    }
}
void prin_new_line(vector<ll>& a)
{
    for(int i=0;i<a.size();i++)
    {
        cout << a[i]<<"\n";
    }
}

int sum_vec(vector<int>& a)
{
    int s=0;
    for(int i=0;i<a.size();i++)
    {
        s+=a[i];
    }
    return s;
}
int min(int a,int b,int c)
{
    return min(a,min(b,c));
}
ll min(ll a,ll b,ll c)
{
    return min(a,min(b,c));
}
int max(int a,int b,int c)
{
    return max(a,max(b,c));
}
ll max(ll a,ll b,ll c)
{
    return max(a,max(b,c));
}
#define FILE "cinema"
#define debug 0
int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0);
   cout.tie(0);
    //  freopen(FILE".in","r",stdin);
   // freopen(FILE".out","w",stdout);
   int n;
   cin >> n;
   int m=ceil(n/2.0);
   map<int,int> fi,se;
   set<int> a;
   for(int i=0;i<n;i++)
   {
       int x;
       cin >> x;
       int y;
       cin >> y;
       fi[x]++;
       se[y]++;
       a.insert(x);
       a.insert(y);
   }
   int ans=inf_int;
   for(set<int>::iterator it=a.begin();it!=a.end();it++)
   {
       int i=*it;
       if(fi[i]+se[i]>=m)
       {
           ans=min(ans,m-fi[i]);
       }
   }
   cout << ans;

}


#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <unordered_map>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
using namespace std;
#define fast {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define ll  long long
#define EPS (1e-8);
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) ((int)(x.size()))
#define REP(i,v) for(int i = 0 ; i < sz(v) ; ++i)
#define neg(x) memset(x,-1,sizeof(x));
#define read(file) freopen (file,"r",stdin)
#define write(file) freopen (file,"w",stdout)
#define INF (1 << 30)
#define endl "\n"
#define all(v) ((v.begin()),v.end())
#define M(x,y) make_pair(x,y)
typedef vector<int> vi;
typedef pair<int,int> ii;
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
#define MAXN 200005
#define top first
#define bot second
pair<int,int> arr[MAXN];
map<int,int> accBot;
map<int,int> accTop;
map<int,int> same;
int n;

bool can(int t)
{

	for(int i = 0 ; i < n ; ++i)
	{
		int tp = arr[i].top;
		int bt = arr[i].bot;
		if(-same[tp] + accTop[tp] + min(t,accBot[tp]) >= ((n + 1) / 2))
			return 1;
		if(-same[bt] + accTop[bt] + min(t,accBot[bt]) >= ((n + 1) / 2))
			return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	int a,b;
	for(int i = 0 ; i < n ; ++i)
	{
		scanf("%d %d",&a,&b);
		arr[i] = make_pair(a,b);
		if(accTop.find(a) == accTop.end()) accTop[a] = 0;
		if(accBot.find(b) == accBot.end()) accBot[b] = 0;
		if(a == b) same[a]++;
		accTop[a]++;
		accBot[b]++;
	}

	int lo = 0;
	int hi = n;
	int ans = -1;
	while(lo <= hi)
	{
		int mid = lo + ( (hi - lo) >> 1);
		if(can(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}
	printf("%d\n",ans);

}


#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <unordered_map>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
using namespace std;
#define fast {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define ll  long long
#define EPS (1e-8);
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) ((int)(x.size()))
#define REP(i,v) for(int i = 0 ; i < sz(v) ; ++i)
#define neg(x) memset(x,-1,sizeof(x));
#define read(file) freopen (file,"r",stdin)
#define write(file) freopen (file,"w",stdout)
#define INF (1 << 30)
#define endl "\n"
#define all(v) ((v.begin()),v.end())
#define M(x,y) make_pair(x,y)
typedef vector<int> vi;
typedef pair<int,int> ii;
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
#define MAXN 200005
#define top first
#define bot second
pair<int,int> arr[MAXN];
int accBot[MAXN];
int accTop[MAXN];
int same[MAXN];
map<int,int> comp;
int n;

bool can(int t)
{

	for(int i = 0 ; i < n ; ++i)
	{
		int tp = arr[i].top;
		int bt = arr[i].bot;
		if(accTop[tp] + min(t,accBot[tp] - same[tp]) >= ((n + 1) / 2))
			return 1;
		if(accTop[bt] + min(t,accBot[bt] - same[bt]) >= ((n + 1) / 2))
			return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	int a,b;

	int id = 0;
	for(int i = 0 ; i < n ; ++i)
	{
		scanf("%d %d",&a,&b);

		if(comp.find(a) == comp.end()) comp[a] = id++;
		if(comp.find(b) == comp.end()) comp[b] = id++;
		a = comp[a];
		b = comp[b];
		arr[i] = make_pair(a,b);
		if(a == b) same[a]++;
		accTop[a]++;
		accBot[b]++;
	}

	int lo = 0;
	int hi = n;
	int ans = -1;
	while(lo <= hi)
	{
		int mid = lo + ( (hi - lo) >> 1);
		if(can(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}
	printf("%d\n",ans);

}


#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <unordered_map>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
using namespace std;
#define fast {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define ll  long long
#define EPS (1e-8);
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) ((int)(x.size()))
#define REP(i,v) for(int i = 0 ; i < sz(v) ; ++i)
#define neg(x) memset(x,-1,sizeof(x));
#define read(file) freopen (file,"r",stdin)
#define write(file) freopen (file,"w",stdout)
#define INF (1 << 30)
#define endl "\n"
#define all(v) ((v.begin()),v.end())
#define M(x,y) make_pair(x,y)
typedef vector<int> vi;
typedef pair<int,int> ii;
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
#define MAXN 200005
#define top first
#define bot second
pair<int,int> arr[MAXN];
map<int,int> accBot;
map<int,int> accTop;
map<int,int> same;
int n;

bool can(int t)
{

	for(int i = 0 ; i < n ; ++i)
	{
		int tp = arr[i].top;
		int bt = arr[i].bot;
		if(accTop[tp] + min(t,accBot[tp] - same[tp]) >= ((n + 1) / 2))
			return 1;
		if(accTop[bt] + min(t,accBot[bt] - same[bt]) >= ((n + 1) / 2))
			return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	int a,b;

	for(int i = 0 ; i < n ; ++i)
	{
		scanf("%d %d",&a,&b);
		arr[i] = make_pair(a,b);
		if(accTop.find(a) == accTop.end()) accTop[a] = 0;
		if(accBot.find(b) == accBot.end()) accBot[b] = 0;
		if(a == b) same[a]++;
		accTop[a]++;
		accBot[b]++;
	}
	map<int,int>::iterator it = accTop.begin();
	for(;it!= accTop.end();it++)
	{
		if((it->second) >= ((n + 1) / 2))
			return puts("0");
	}
	int lo = 0;
	int hi = n;
	int ans = -1;
	while(lo <= hi)
	{
		int mid = lo + ( (hi - lo) >> 1);
		if(can(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}
	printf("%d\n",ans);

}


#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <unordered_map>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
using namespace std;
#define fast {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define ll  long long
#define EPS (1e-8);
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) ((int)(x.size()))
#define REP(i,v) for(int i = 0 ; i < sz(v) ; ++i)
#define neg(x) memset(x,-1,sizeof(x));
#define read(file) freopen (file,"r",stdin)
#define write(file) freopen (file,"w",stdout)
#define INF (1 << 30)
#define endl "\n"
#define all(v) ((v.begin()),v.end())
#define M(x,y) make_pair(x,y)
typedef vector<int> vi;
typedef pair<int,int> ii;
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
#define MAXN 200005
#define top first
#define bot second
pair<int,int> arr[MAXN];
map<int,int> accBot;
map<int,int> accTop;
map<int,int> same;
int n;

bool can(int t)
{

	for(int i = 0 ; i < n ; ++i)
	{
		int tp = arr[i].top;
		int bt = arr[i].bot;
		if(accTop[tp] + min(t,accBot[tp] - same[bt]) >= ((n + 1) / 2))
			return 1;
		if(accTop[bt] + min(t,accBot[bt] - same[tp]) >= ((n + 1) / 2))
			return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	int a,b;

	for(int i = 0 ; i < n ; ++i)
	{
		scanf("%d %d",&a,&b);
		arr[i] = make_pair(a,b);
		if(accTop.find(a) == accTop.end()) accTop[a] = 0;
		if(accBot.find(b) == accBot.end()) accBot[b] = 0;
		if(a == b) same[a]++;
		accTop[a]++;
		accBot[b]++;
	}
	map<int,int>::iterator it = accTop.begin();
	for(;it!= accTop.end();it++)
	{
		if((it->second) >= ((n + 1) / 2))
			return puts("0");
	}
	int lo = 0;
	int hi = n;
	int ans = -1;
	while(lo <= hi)
	{
		int mid = lo + ( (hi - lo) >> 1);
		if(can(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}
	printf("%d\n",ans);

}


#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <unordered_map>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
using namespace std;
#define fast {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define ll  long long
#define EPS (1e-8);
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) ((int)(x.size()))
#define REP(i,v) for(int i = 0 ; i < sz(v) ; ++i)
#define neg(x) memset(x,-1,sizeof(x));
#define read(file) freopen (file,"r",stdin)
#define write(file) freopen (file,"w",stdout)
#define INF (1 << 30)
#define endl "\n"
#define all(v) ((v.begin()),v.end())
#define M(x,y) make_pair(x,y)
typedef vector<int> vi;
typedef pair<int,int> ii;
inline int toInt(string s){int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
#define MAXN 200005
#define top first
#define bot second
pair<int,int> arr[MAXN];
map<int,int> accBot;
map<int,int> accTop;
map<int,int> same;
int n;

bool can(int t)
{

	for(int i = 0 ; i < n ; ++i)
	{
		int tp = arr[i].top;
		int bt = arr[i].bot;
		if(-same[tp] + accTop[tp] + min(t,accBot[tp]) >= ((n + 1) / 2))
			return 1;
		if(-same[bt] + accTop[bt] + min(t,accBot[bt]) >= ((n + 1) / 2))
			return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	int a,b;

	for(int i = 0 ; i < n ; ++i)
	{
		scanf("%d %d",&a,&b);
		arr[i] = make_pair(a,b);
		if(accTop.find(a) == accTop.end()) accTop[a] = 0;
		if(accBot.find(b) == accBot.end()) accBot[b] = 0;
		if(a == b) same[a]++;
		accTop[a]++;
		accBot[b]++;
	}
	map<int,int>::iterator it = accTop.begin();
	for(;it!= accTop.end();it++)
	{
		if((it->second) >= ((n + 1) / 2))
			return puts("0");
	}
	int lo = 0;
	int hi = n;
	int ans = -1;
	while(lo <= hi)
	{
		int mid = lo + ( (hi - lo) >> 1);
		if(can(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}
	printf("%d\n",ans);

}


mod=10**9+7
n=int(input())
#dp[index][indent]
dp=[[0 for i in range(n+1) ]for j in range(n+1)]
dp[0][0]=1
s=[]
for i in range(n):
    s.append(input())

for i in range(1,n+1):
    if s[i-1]!='f':
        c=0
        for j in range(n-1,-1,-1):
            dp[i][j]=(c+dp[i-1][j])
            c+=dp[i-1][j]
            c%=mod
            dp[i][j]%=mod
    else:
        for j in range(n+1):

            dp[i][j]=dp[i-1][j-1]
        dp[i][0]=0

print(sum(dp[n-1])%mod)


mod=10**9+7
n=int(input())
#dp[index][indent]
dp=[[0 for i in range(n+1) ]for j in range(n+1)]
dp[1][0]=1
s=[]
for i in range(n):
    s.append(input())
x=s[0]
for i in range(1,n):
    if x!='f':

        for j in range(n):
            for p in range(j,n):

                dp[i+1][j]=(dp[i+1][j]+dp[i][p])%mod
    else:
        for j in range(n):

            dp[i+1][j]=dp[i][j-1]
    x=s[i]

print(sum(dp[n])%mod)


def add(a,b):
	a = a%(1000000000+7)
	b=b%(1000000000+7)
	return (a+b)%(1000000000+7)

n  =int(input())
i=1
statements = []
dp = [[0 for i in range(n)] for i in range(n)]
prefix = [[0 for i in range(n)] for i in range(n)]
while(i<=n):
	s = input()
	statements.append(s)
	i+=1

dp[0][0]=1
prefix[0][0]=1
j=1
while(j<n):
	dp[0][j]=0
	prefix[0][j] = dp[0][j] + prefix[0][j-1]
	j+=1

i=1
while(i<n):
	if(statements[i-1]=='f'):
		j=1
		while(j<n):
			dp[i][0]=0
			prefix[i][0]=0
			dp[i][j] = dp[i-1][j-1]
			prefix[i][j] = add(prefix[i][j-1],dp[i][j])

			j+=1
	else:
		j=0
		while(j<n):
			if(j==0):
				dp[i][j] = prefix[i-1][n-1]
			else:
				dp[i][j] = prefix[i-1][n-1] - prefix[i-1][j-1]
			prefix[i][j] = add(prefix[i][j-1],dp[i][j])
			j+=1
	# print(prefix)
	i+=1

# i=0
# while(i<n):
# 	j=0
# 	while(j<n):
# 		print(dp[i][j])
# 		j+=1
# 	i+=1

# print(dp)

ans = 0
j=0
while(j<n):
	ans=add(ans,dp[n-1][j])
	j+=1

print(ans%(1000000000+7))


import os, sys, atexit
# from io import BytesIO, StringIO
# from sys import stdin, stdout

# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
# _OUTPUT_BUFFER = StringIO()
# sys.stdout = _OUTPUT_BUFFER

# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5001 for x in range(5001)]
def calculate(level,i):
    if (i>=len(inputs)):
        return 0
    if dp[level][i]==0:
        if inputs[i]=='f':
            dp[level][i] = calculate(level+1,i+1)
        else:
            for x in range(level,0,-1):
                dp[level][i]=(dp[level][i]+calculate(x,i+1))%1000000007
            dp[level][i]=max(1,dp[level][i])
    return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        inputs.append(input())
    print (calculate(1,0))
try:
    solve()
except Exception as e:
    print (e)

# solve()


import os, sys, atexit
# from io import BytesIO, StringIO
# from sys import stdin, stdout

# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
# _OUTPUT_BUFFER = StringIO()
# sys.stdout = _OUTPUT_BUFFER

# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5002 for _ in range(5002)]
# def calculate(level,i):
#     if (i>=len(inputs)):
#         return 0
#     if dp[level][i]==0:
#         ans = 0
#         if inputs[i]=='f':
#             ans = calculate(level+1,i+1)
#         else:
#             for x in range(level,0,-1):
#                 ans=(ans+calculate(x,i+1))%1000000007
#             ans=max(1,ans)
#         dp[level][i] = ans
#     return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        inputs.append(input())
    for i in range(n-1,-1,-1):
        for level in range(1,n+1):
            ans = 0
            if inputs[i]=='f':
                ans = dp[level+1][i+1]- dp[level][i+1]
            else:
                ans=max(1,dp[level][i+1])
            dp[level][i] = (ans+dp[level-1][i])%1000000007
    print (dp[1][0])
try:
    solve()
except Exception as e:
    print (e)

# solve()


import os, sys, atexit
# from io import BytesIO, StringIO
# from sys import stdin, stdout

# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
# _OUTPUT_BUFFER = StringIO()
# sys.stdout = _OUTPUT_BUFFER

# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5002 for _ in range(5002)]
# def calculate(level,i):
#     if (i>=len(inputs)):
#         return 0
#     if dp[level][i]==0:
#         ans = 0
#         if inputs[i]=='f':
#             ans = calculate(level+1,i+1)
#         else:
#             for x in range(level,0,-1):
#                 ans=(ans+calculate(x,i+1))%1000000007
#             ans=max(1,ans)
#         dp[level][i] = ans
#     return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        inputs.append(input())
    for i in range(n-1,-1,-1):
        for level in range(1,n+1):
            ans = 0
            if inputs[i]=='f':
                ans = dp[level+1][i+1]
            else:
                for x in range(level,0,-1):
                    ans=(ans+dp[x][i+1])%1000000007
                ans=max(1,ans)
            dp[level][i] = ans
    print (dp[1][0])
try:
    solve()
except Exception as e:
    print (e)

# solve()


import os, sys, atexit
from io import BytesIO, StringIO
from sys import stdin, stdout

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5002 for _ in range(5002)]
# def calculate(level,i):
#     if (i>=len(inputs)):
#         return 0
#     if dp[level][i]==0:
#         ans = 0
#         if inputs[i]=='f':
#             ans = calculate(level+1,i+1)
#         else:
#             for x in range(level,0,-1):
#                 ans=(ans+calculate(x,i+1))%1000000007
#             ans=max(1,ans)
#         dp[level][i] = ans
#     return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        inputs.append(input())
    for i in range(n-1,-1,-1):
        for level in range(1,n+1):
            ans = 0
            if inputs[i]=='f':
                ans = dp[level+1][i+1]
            else:
                for x in range(level,0,-1):
                    ans=(ans+dp[x][i+1])%1000000007
                ans=max(1,ans)
            dp[level][i] = ans
    print (dp[1][0])
try:
    solve()
except Exception as e:
    print (e)

# solve()


import os, sys, atexit
# from io import BytesIO, StringIO
# from sys import stdin, stdout

# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
# _OUTPUT_BUFFER = StringIO()
# sys.stdout = _OUTPUT_BUFFER

# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5001 for _ in range(5001)]
# def calculate(level,i):
#     if (i>=len(inputs)):
#         return 0
#     if dp[level][i]==0:
#         ans = 0
#         if inputs[i]=='f':
#             ans = calculate(level+1,i+1)
#         else:
#             for x in range(level,0,-1):
#                 ans=(ans+calculate(x,i+1))%1000000007
#             ans=max(1,ans)
#         dp[level][i] = ans
#     return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        inputs.append(input())
    for i in range(n-1,-1,-1):
        for level in range(1,n+1):
            ans = 0
            if inputs[i]=='f':
                ans = dp[level+1][i+1]
            else:
                for x in range(level,0,-1):
                    ans=(ans+dp[x][i+1])%1000000007
                ans=max(1,ans)
            dp[level][i] = ans
    print (dp[1][0])
try:
    solve()
except Exception as e:
    print (e)

# solve()


import os, sys, atexit
from io import BytesIO, StringIO
from sys import stdin, stdout

# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
# _OUTPUT_BUFFER = StringIO()
# sys.stdout = _OUTPUT_BUFFER

# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5002 for _ in range(5002)]
# def calculate(level,i):
#     if (i>=len(inputs)):
#         return 0
#     if dp[level][i]==0:
#         ans = 0
#         if inputs[i]=='f':
#             ans = calculate(level+1,i+1)
#         else:
#             for x in range(level,0,-1):
#                 ans=(ans+calculate(x,i+1))%1000000007
#             ans=max(1,ans)
#         dp[level][i] = ans
#     return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        # new = input()
        inputs.append(stdin.readline().strip())
    for i in range(n-1,-1,-1):
        for level in range(1,n+1):
            ans = 0
            if inputs[i]=='f':
                ans = dp[level+1][i+1]
            else:
                for x in range(level,0,-1):
                    ans=(ans+dp[x][i+1])%1000000007
                ans=max(1,ans)
            dp[level][i] = ans
    print (dp[1][0])
try:
    solve()
except Exception as e:
    print (e)

# solve()


import os, sys, atexit
from io import BytesIO, StringIO
from sys import stdin, stdout

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
# sys.setrecursionlimit(6000)
inputs = []
dp = [[0]*5002 for _ in range(5002)]
# def calculate(level,i):
#     if (i>=len(inputs)):
#         return 0
#     if dp[level][i]==0:
#         ans = 0
#         if inputs[i]=='f':
#             ans = calculate(level+1,i+1)
#         else:
#             for x in range(level,0,-1):
#                 ans=(ans+calculate(x,i+1))%1000000007
#             ans=max(1,ans)
#         dp[level][i] = ans
#     return dp[level][i]

def solve():
    n = int(input())
    for _ in range(n):
        new = input()
        inputs.append(new)
    for i in range(n-1,-1,-1):
        for level in range(1,n+1):
            ans = 0
            if inputs[i]=='f':
                ans = dp[level+1][i+1]
            else:
                for x in range(level,0,-1):
                    ans=(ans+dp[x][i+1])%1000000007
                ans=max(1,ans)
            dp[level][i] = ans
    print (dp[1][0])
try:
    solve()
except Exception as e:
    print (e)

# solve()


import sys
sys.setrecursionlimit(1000000)
read = sys.stdin.readline

MOD = 1000000007

N = int(read())
sts = [read().strip() for _ in range(N)]

ind = [0 for _ in range(N)]
ind[0] = 1
indent = 0
last = 'f'
for st in sts:
    if last != 'f':
        for i in range(indent, -1, -1):
            ind[i] += ind[i+1]
            ind[i] %= MOD
    if st == 'f':
        indent += 1
        for i in range(indent, 0, -1):
            ind[i] += ind[i-1]
            ind[i-1] = 0
    last = st
    # print(ind)

ans = 0
for i in range(indent+1):
    ans += ind[i]
    ans %= MOD
print(ans)


n = int(input())
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]

dp[0][0] = 1
for i in range(0, n) :
    a = input()
    if a == 'f' :
        for j in range(1, n) :
            dp[i + 1][j] = dp[i][j - 1]
    else :
        suf = 0
        for j in range(n - 1, -1, -1) :
            suf = suf + dp[i][j]
            dp[i + 1][j] = dp[i + 1][j] + suf

print(sum([x for x in dp[n - 1]]))

# run : python wtf.py


n = int(input())
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]

dp[0][0] = 1
for i in range(0, n) :
    a = input()
    if a == 'f' :
        for j in range(1, n) :
            dp[i + 1][j] = dp[i][j - 1]
    else :
        suf = 0
        for j in range(n - 1, -1, -1) :
            suf = (suf + dp[i][j]) % 1000000007
            dp[i + 1][j] = (dp[i + 1][j] + suf) % 1000000007

print(sum([x for x in dp[n - 1]]))

# run : python wtf.py


n = int(input())
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]

dp[0][0] = 1
for i in range(0, n) :
    a = input()
    if a == 'f' :
        for j in range(1, n) :
            dp[i + 1][j] = dp[i][j - 1]
    else :
        suf = 0
        for j in range(n - 1, 0, -1) :
            suf = suf + dp[i][j]
            dp[i + 1][j] = dp[i + 1][j] + suf

print(sum([x for x in dp[n]]))

# run : python wtf.py


n = int(input())
dp = [[0 for i in range(n + 1)] for j in range(n + 1)]

dp[0][0] = 1
for i in range(0, n) :
    a = input()
    if a == 'f' :
        for j in range(1, n) :
            dp[i + 1][j] = dp[i][j - 1]
    else :
        suf = 0
        for j in range(n - 1, -1, -1) :
            suf = (suf + dp[i][j]) % 1000000007
            dp[i + 1][j] = (dp[i + 1][j] + suf) % 1000000007

print(sum([x for x in dp[n - 1]]) % 1000000007)

# run : python wtf.py


import math
MOD=int(1e9+7)
n=int(input())
a=[]
prev='c'
for _ in range(n):
    c=input()
    if c=='f' and prev=='f':
        pass
    elif prev=='f' and c=='s':
        pass
    else:
        a.append(c)
    prev = c
n = len(a)

#depth = [0]*n
#for i in range(1,n):
#    if a[i-1]=='f':
#        depth[i]=depth[i-1]+1
#    else:
#        depth[i]=depth[i-1]

consta = 5000+1
levels = [0]*consta
levels[0]+=1
for i in range(1,n):
    if a[i-1]=='f':
        cumsum = 0
        for j in reversed(range(consta-1)):
            cumsum += levels[j]
            cumsum%=MOD
            levels[j+1] = cumsum
        levels[0] = 0
    else:
        cumsum = 0
        for j in reversed(range(consta)):
            cumsum += levels[j]
            cumsum%=MOD
            levels[j] = cumsum

print(sum(levels)%MOD)

#seq = []
#ind = 0
#while ind<n:
#    while ind<n and a[ind]!='f':
#        ind+=1
#    if ind>=n:break
#    count = 0
#    while ind<n and a[ind]=='f':
#        count+=1
#        ind+=1
#    seq.append(count)
#if len(seq)>0:
#    print(pow(2,len(seq)-1,MOD))
#else:
#    print(1)


import math
MOD=int(1e9+7)
n=int(input())
a=[]
for _ in range(n):
    a.append(input())

seq = []
ind = 0
while ind<n:
    while ind<n and a[ind]!='f':
        ind+=1
    if ind>=n:break
    count = 0
    while ind<n and a[ind]=='f':
        count+=1
        ind+=1
    seq.append(count)
if len(seq)>0:
    print(pow(2,len(seq)-1,MOD))
else:
    print(1)


n = int(input())
a = [input() for _ in range(n)]

MOD = int(1e9+7)
const = 5001
levels = [0]*const
levels[0] = 1

for i in range(n-1):
    if a[i]=='f':
        for j in range(const-2,-1,-1):
            levels[j+1]=levels[j]
        levels[0]=0
    else:
        cumsum = 0
        for j in range(const-1,-1,-1):
            cumsum += levels[j]
            cumsum%=MOD
            levels[j]=cumsum
print(sum(levels)%MOD)


import math
MOD=int(1e9+7)
n=int(input())
a=[]
for _ in range(n):
    a.append(input())

seq = []
ind = 0
while ind<n:
    while ind<n and a[ind]!='f':
        ind+=1
    if ind>=n:break
    count = 0
    while ind<n and a[ind]=='f':
        count+=1
        ind+=1
    seq.append(count)
if seq:
    print(pow(2,len(seq)-1,MOD))
else:
    print(1)


import math
MOD=int(1e9+7)
n=int(input())
a=[]
prev='c'
for _ in range(n):
    c=input()
    if c=='f' and prev=='f':
        pass
    elif prev=='f' and c=='s':
        pass
    else:
        a.append(c)
    prev = c
n = len(a)

outs = 0
ins = 1
for i in range(n):
    if a[i]=='s':
        outs,ins = outs,(ins+outs)%MOD
    else:
        outs,ins = (2*outs+ins)%MOD,0
print(outs+ins)

#
#seq = []
#ind = 0
#while ind<n:
#    while ind<n and a[ind]!='f':
#        ind+=1
#    if ind>=n:break
#    count = 0
#    while ind<n and a[ind]=='f':
#        count+=1
#        ind+=1
#    seq.append(count)
#if len(seq)>0:
#    print(pow(2,len(seq)-1,MOD))
#else:
#    print(1)


import math
MOD=int(1e9+7)
n=int(input())
a=[]
prev='c'
for _ in range(n):
    c=input()
    if c=='f' and prev=='f':
        pass
    elif prev=='f' and c=='s':
        pass
    else:
        a.append(c)
    prev = c
n = len(a)

#depth = [0]*n
#for i in range(1,n):
#    if a[i-1]=='f':
#        depth[i]=depth[i-1]+1
#    else:
#        depth[i]=depth[i-1]

consta = 5000+1
levels = [0]*consta
levels[0]+=1
for i in range(1,n):
    if a[i-1]=='f':
        cumsum = 0
        for j in reversed(range(consta-1)):
            cumsum += levels[j]
            levels[j+1] = cumsum
        levels[0] = cumsum
    else:
        cumsum = 0
        for j in reversed(range(consta)):
            cumsum += levels[j]
            levels[j] = cumsum

print(sum(levels))

#seq = []
#ind = 0
#while ind<n:
#    while ind<n and a[ind]!='f':
#        ind+=1
#    if ind>=n:break
#    count = 0
#    while ind<n and a[ind]=='f':
#        count+=1
#        ind+=1
#    seq.append(count)
#if len(seq)>0:
#    print(pow(2,len(seq)-1,MOD))
#else:
#    print(1)


import math
MOD=int(1e9+7)
n=int(input())
a=[]
prev='c'
for _ in range(n):
    c=input()
    if c=='f' and prev=='f':
        pass
    elif prev=='f' and c=='s':
        pass
    else:
        a.append(c)
    prev = c
n = len(a)

#depth = [0]*n
#for i in range(1,n):
#    if a[i-1]=='f':
#        depth[i]=depth[i-1]+1
#    else:
#        depth[i]=depth[i-1]

consta = 5000+1
levels = [0]*consta
levels[0]+=1
for i in range(1,n):
    if a[i-1]=='f':
        cumsum = 0
        for j in reversed(range(consta-1)):
            cumsum += levels[j]
            cumsum%=MOD
            levels[j+1] = cumsum
        levels[0] = cumsum
    else:
        cumsum = 0
        for j in reversed(range(consta)):
            cumsum += levels[j]
            cumsum%=MOD
            levels[j] = cumsum

print(sum(levels)%MOD)

#seq = []
#ind = 0
#while ind<n:
#    while ind<n and a[ind]!='f':
#        ind+=1
#    if ind>=n:break
#    count = 0
#    while ind<n and a[ind]=='f':
#        count+=1
#        ind+=1
#    seq.append(count)
#if len(seq)>0:
#    print(pow(2,len(seq)-1,MOD))
#else:
#    print(1)


import bisect

def list_output(s):
    print(' '.join(map(str, s)))

def list_input(s='int'):
    if s == 'int':
        return list(map(int, input().split()))
    elif s == 'float':
        return list(map(float, input().split()))
    return list(map(str, input().split()))

n = int(input())
MOD = int(1e9)+7

seq = list()
for i in range(n):
    seq.append(list(map(str, input().split()))[0])

dp = [[0 for j in range(n+1)] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    ps = [0 for j in range(n+1)]
    for j in range(n):
        ps[j+1] = (ps[j] + dp[i][j])%MOD
    for j in range(n):
        if i > 0 and seq[i-1] == 'f':
            dp[i+1][j+1] += dp[i][j]
            dp[i+1][j+1] %= MOD
        else:
            dp[i+1][j] += ps[n] - ps[j]

res = 0
for i in range(n+1):
    res += dp[n][i]
    res %= MOD
print(res)


import bisect

def list_output(s):
    print(' '.join(map(str, s)))

def list_input(s='int'):
    if s == 'int':
        return list(map(int, input().split()))
    elif s == 'float':
        return list(map(float, input().split()))
    return list(map(str, input().split()))

n = int(input())
MOD = int(1e9)+7

seq = list()
for i in range(n):
    seq.append(list(map(str, input().split()))[0])

dp = [[0 for j in range(n+1)] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(n):
        if i > 0 and seq[i-1] == 'f':
            dp[i+1][j+1] += dp[i][j]
            dp[i+1][j+1] %= MOD
        else:
            for k in range(j+1):
                dp[i+1][k] += dp[i][j]
                dp[i+1][k] %= MOD

res = 0
for i in range(n+1):
    res += dp[n][i]
    res %= MOD
print(res)


n = int(input())
res = 1; fc = 0
mod = 10 ** 9 + 7
s = 'x'
for i in range(n):
    s += input()
    if s[-1] == 's' and s[-2] != 'f':
        res = (res * max(fc, 1)) % mod
    elif s[-1] == 'f':
        fc += 1
        if s[-2] != 'f':
            res = (res * max(fc, 1)) % mod
print(res)


n = int(input())
a = []
for _ in range(n):
    a.append(input())
dp = []
dp.append([1])
for i in range(1, n):
    if a[i - 1] == 'f':
        dp.append([0] + dp[i - 1])
    else:
        m = len(dp[i - 1])
        dp.append([0] * m)
        dp[-1][-1] = dp[i - 1][-1]
        for j in range(m - 2, -1, -1):
            dp[-1][j] = dp[i - 1][j] + dp[i][j + 1]
print(sum(dp[-1]))


MOD = 1000000007

n = int(input())
a = []
for _ in range(n):
    a.append(input())
dp = []
dp.append([1])
for i in range(1, n):
    if a[i - 1] == 'f':
        dp.append([0] + dp[i - 1])
    else:
        m = len(dp[i - 1])
        dp.append([0] * m)
        dp[-1][-1] = dp[i - 1][-1]
        for j in range(m - 2, -1, -1):
            dp[-1][j] = (dp[i - 1][j] + dp[i][j + 1]) % MOD
print(sum(dp[-1]) % MOD)


n = int(input())

MODULO = 10 ** 9 + 7
i = 0
dp = [[0 for i in range(n + 2)] for j in range(n + 2)]
dp[0][0] = 1

new_array = [0] * (n + 2)
old_array = [0] * (n + 2)
new_array[0] = 1

for i in range(n):
    c = input()[0]
    old_array = new_array
    new_array = [0] * (n + 2)
    if c == 'f':
        for j in range(n):
            new_array[j + 1] = old_array[j]
    else:
        j = i + 1
        tmp = 0
        while j >= 0:
            tmp = (tmp + old_array[j]) % MODULO
            new_array[j] = tmp % MODULO
            j -= 1
    #print(old_array)

tmp = 0

for i in range(n):
    tmp = (tmp + old_array[i]) % MODULO
print(tmp)


n = int(input())
i = 0
dp = [[0 for i in range(n + 2)] for j in range(n + 2)]
dp[0][0] = 1
for i in range(n):
    c = input()[0]
    if c == 'f':
        for j in range(n):
            dp[i + 1][j + 1] = dp[i][j]
    else:
        j = i + 1
        tmp = 0
        while j >= 0:
            tmp += dp[i][j]
            dp[i + 1][j] = tmp
            j -= 1
tmp = 0
#for i in range(n + 1):
#    print(dp[i])

MODULO = 10 ** 9 + 7

for i in range(n):
    tmp = (tmp + dp[n - 1][i]) % MODULO
print(tmp)


n = int(input())
i = 0
dp = [[0 for i in range(n + 2)] for j in range(n + 2)]
dp[0][0] = 1

new_array = [0] * (n + 2)
old_array = [0] * (n + 2)
new_array[0] = 1

for i in range(n):
    c = input()[0]
    old_array = new_array
    new_array = [0] * (n + 2)
    if c == 'f':
        for j in range(n):
            new_array[j + 1] = old_array[j]
    else:
        j = i + 1
        tmp = 0
        while j >= 0:
            tmp += old_array[j]
            new_array[j] = tmp
            j -= 1
    #print(old_array)

tmp = 0

MODULO = 10 ** 9 + 7

for i in range(n):
    tmp = (tmp + old_array[i]) % MODULO
print(tmp)


n = int(input())
dp = [1]
for IND in range(n):
    c = input()
    if c == "f":
        dp.insert(0,0)
    else:
        for i in range(len(dp)-2, -1, -1): dp[i] = (dp[i] + dp[i+1]) % 1000000007
print(dp[0])


import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n=int(input())
b=[]
for j in range(n):
    b.append(input())
ans=1
j=0
res=0
p=10**9+7
dp=[[0]*(n) for i in range(n)]
dp[0][0]=1
j=1
while(j<n):
    if b[j-1]=="f":
        dp[j][0]=0
        for i in range(1,n):
            dp[j][i]=(dp[j-1][i-1])
    else:
        q=sum(dp[j-1])
        for i in range(n):
            dp[j][i] = q
            q-=dp[j-1][i]
    j+=1

print(sum(dp[n-1])%p)


n=int(input())
b=[]
for j in range(n):
    b.append(input())
ans=1
j=0
res=0
p=10**9+7
dp=[[0]*(n) for i in range(n)]
dp[0][0]=1
j=1
while(j<n):
    if b[j-1]=="f":
        dp[j][0]=0
        for i in range(1,n):
            dp[j][i]=dp[j-1][i-1]
    else:
        q=sum(dp[j-1])
        for i in range(n):
            dp[j][i] = q
            q-=dp[j-1][i]
    j+=1

print(sum(dp[n-1])%p)


n=int(input())
b=[]
for j in range(n):
    b.append(input())
ans=1
j=0
res=1
p=10**9+7
dp=[0]*(n)
dp[0]=1
while(j<n):
    if b[j]=="f":
        res+=1

    else:
        for i in range(1,res):
            dp[i]=(dp[i]+dp[i-1])%(p)
    j+=1

print(dp[res-1]%p)


import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n=int(input())
b=[]
for j in range(n):
    b.append(input())
ans=1
j=0
res=0
p=10**9+7
dp=[[0]*(n) for i in range(n)]
dp[0][0]=1
j=1
while(j<n):
    if b[j-1]=="f":
        dp[j][0]=0
        for i in range(1,n):
            dp[j][i]=(dp[j-1][i-1])
    else:
        q=sum(dp[j-1])
        for i in range(n):
            dp[j][i] = q
            q-=dp[j-1][i]
    j+=1

print(sum(dp[n-1])%p)


n=int(input())
b=[]
for j in range(n):
    b.append(input())
ans=1
j=0
res=0
p=10**9+7
dp=[[0]*(n) for i in range(n)]
dp[0][0]=1
j=1
while(j<n):
    if b[j-1]=="f":
        dp[j][0]=0
        for i in range(1,n):
            dp[j][i]=dp[j-1][i-1]
    else:
        q=sum(dp[j-1])
        for i in range(n):
            dp[j][i] = q
            q-=dp[j-1][i]
    j+=1
print(dp)
print(sum(dp[n-1])%p)


n = int(input())
A = []

for i in range(n):
    x = input()
    A.append(x)

dp = [[0 for i in range(n+1)] for j in range(n+1)]

mod = 10**9 + 7

for i in range(n+1):
    dp[n-1][i] = 1

for line in range(n-2, -1, -1):
    sum = 0
    if A[line]=='s':
        for indent in range(n):
            sum = (sum + dp[line+1][indent])%mod
            dp[line][indent] = sum
    else:
        for indent in range(n):
            dp[line][indent] = dp[line+1][indent+1]

print(dp[0][0])


# DP 1

# n = int(input())
# dp = [1]
# for i in range(n):
#     c = input()
#     if c == "f":
#         dp.insert(0,0)
#     else:
#         for j in range(len(dp) - 2, -1, -1):
#             dp[j] = (dp[j] + dp[j + 1]) % 1000000007
#     print(dp)
# print(dp[0])

n = int(input())
dp = [1]
for i in range(n):
    c = input()
    if c == "f":
        dp.append(0)
    else:
        for j in range(1, len(dp)):
            dp[j] = (dp[j] + dp[j - 1]) % 1000000007
print(dp[-1])


n = int(input())
dp = [1]
for i in range(n):
    c = input()
    if c == "f":
        dp.insert(0,0)
    else:
        for j in range(len(dp) - 2, -1, -1):
            dp[j] = (dp[j] + dp[j + 1]) % 1000000007
print(dp[0])