/*=================================
# Created time: 2018-07-13 22:33
# Filename: a.cpp
# Description:
=================================*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define pii pair<int, int>
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define fin(a) freopen(a,"r",stdin);
#define fout(a) freopen(a,"w",stdout);
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)

#define maxn 100005
#define maxm 100005
#define MOD 1000000007
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> inline
void read(T& num){
    num = 0; bool f = 1;char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
    num = f ? num: -num;
}
template<class T> inline
void write(T x,char ch){
	int s[100];
	if (x==0) {putchar('0'); putchar(ch); return;}
	if (x<0) {putchar('-'); x=-x;} int num=0;
	while (x){ s[num++]=(x%10); x=x/10;}
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch);
}
/*==================split line==================*/
const double pi = acos(-1);
const double eps = 1e-8;
 int cnt = 1;
 int c[maxn], a[maxn];
int main(){
	int n; read(n);
	FORP(i, 1, n) read(a[i]);
	sort(a + 1, a + 1 + n);
	c[1] = 1;
	FORP(i, 2, n) {
		if (a[i] != a[i - 1]) cnt++;
		c[cnt]++;
	}
	//FORP(i, 1, cnt) write(c[i],' ');
	FORP(i, 2, cnt) c[i] += c[i - 1];
	int ans = 0;
	FORP(i, 1, cnt) ans = max(ans, min(c[i], n - c[i]));
	write(ans,'\n');
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define memset(X,Y) memset(X,Y,sizeof X)
#define all(X) X.begin(),X.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define ve vector<int>
#define pii pair<int,int>
#define ll long long
using namespace std;
int const N = 1e5 + 50;
pii p[N];
map<ll,ll> mpi;
ll n,a[N],vis[N],x,y,m;
int main()
{
cin >> n;
for(int i=0;i<n;i++) cin >> a[i];
sort(a,a+n);
ll mn = a[0];
int r = n;
for(int i=(n-1);i>0;i--)
{
  if(a[i]==mn) break;
  r = lower_bound(a,a+r,a[i]) - a;
  r--;
  y++;
}
cout << y;
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define memset(X,Y) memset(X,Y,sizeof X)
#define all(X) X.begin(),X.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define ve vector<int>
#define pii pair<int,int>
#define ll long long
using namespace std;
int const N = 1e5 + 50;
pii p[N];
map<ll,ll> mpi;
ll n,a[N],vis[N],x,y,m;
int main()
{
cin >> n;
for(int i=0;i<n;i++) cin >> a[i] ,mpi[a[i]]++;
sort(a,a+n);
ll mn = a[0];
int r = n;
for(int i=(n-1);i>0;i--)
{
  if(a[i]==mn || r==0) break;
  r = lower_bound(a,a+r,a[i]) - a;
  r--;
  y++;

}
cout << y;
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define memset(X,Y) memset(X,Y,sizeof X)
#define all(X) X.begin(),X.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define ve vector<int>
#define pii pair<int,int>
#define ll long long
using namespace std;
int const N = 1e5 + 50;
pii p[N];
ll n,a[N],vis[N],x,y,m;
int main()
{
cin >> n;
for(int i=0;i<n;i++) cin >> a[i];
sort(a,a+n); x = a[0];
for(int i=0;i<n;i++)
{
    if(a[i] > a[0]) y++;
}
cout << y;
}


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

map<int, bool> mp;

int main()
{
    mp.clear();
    int n, ans = 0, x;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if(!mp[x])  ans++;
        mp[x] = true;
    }
    printf("%d\n", ans == 1 ? 0 : ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5+10;

ll pre[maxn], b[maxn];
map<ll, int> mp;
vector<ll> ans;
struct node
{
    ll x, sum;
}a[maxn];

int main()
{
    int n, num = 0;
    memset(pre, 0, sizeof pre);
    mp.clear();
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        ll xx;
        scanf("%I64d", &xx);
        if(!mp[xx]) {
            mp[xx] = ++num;
            ans.push_back(xx);
        }
        a[mp[xx]].x = xx;   a[mp[xx]].sum++;
    }
    sort(ans.begin(), ans.end());
    ll Ans = 0;
    for(int i = 0; i < ans.size(); i++)
    {
        pre[i+1] = pre[i] + a[mp[ans[i]]].sum;
        b[i+1] = a[mp[ans[i]]].sum;
    }
    for(int i = 2; i <= num; i++)
    {
        Ans += min(b[i], pre[i-1] - Ans);
    }
    cout << Ans <<endl;
    return 0;
}


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

map<int, bool> mp;

int main()
{
    mp.clear();
    int n, ans = 0, x;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if(!mp[x])  ans++;
        mp[x] = true;
    }
    if(ans == 1) ans = 0;
    else if(ans == n)  ans--;
    printf("%d\n", ans);
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int  s=0,c=0;
	for(int i=1;i<n;i++){
	    if(a[i]>a[s]){
	        c++;
	        s++;
	    }
	}
	std::cout << c << std::endl;
	return 0;
}


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

int main() {
	int n;
	cin>>n;
	int a[n+1],h[n+1]={0};
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	int c=0;
	sort(a,a+n);
	for(int i=0;i<n;i++){
	   for(int j=0;j<i;j++){
	      if(h[j]!=1){
	          if(a[i]>a[j]){
	              c++;
	              h[j]=1;
	              break;
	          }

	      }
	   }
	}

	cout<<c;

	return 0;
}


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

int a[100000+10], n;

int main()
{
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    int t, k;
    t=k=0;
    for(i=0;i+k<n;i++)
    {
        if(a[i]<a[i+k]) t++;
        else
        {
            i--;k++;
        }
    }
    printf("%d",t);

}


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

int a[100000+10], n;

int main()
{
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    int t;
    t=a[0];
    for(i=1;i<n;i++)
        if(a[i]!=t) break;
    int k=i;
    t=0;
    for(i=0;i+k<n;i++)
    {
        if(a[i]<a[i+k]) t++;
        else
        {
            i--;k++;
        }
    }
    printf("%d",t);

}


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

int a[100000+10], n;

int main()
{
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    int t;
    t=a[0];
    for(i=1;i<n;i++)
        if(a[i]!=t) break;
    int k=i;
    t=0;
    for(i=0;i+k<n;i++)
    {
        if(a[i]<a[i+k]) t++;
    }
    printf("%d",t);

}


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

int a[100000+10], n;

int main()
{
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    int t;
    t=a[0];
    for(i=1;i<n;i++)
        if(a[i]!=t) break;
    int k=i;
    for(i=0;i+k<n;i++)
    {
        if(a[i]>=a[i+k]) break;
    }
    printf("%d",i);

}


#include<iostream>
#include<cstdio>
#include<fstream>
#include<set>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<iomanip>
#include<cstdlib>
#include<list>
#include<queue>
#include<stack>
#include<algorithm>
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define meminf(a) memset(a,inf,sizeof(a))
//vector ::iterator it;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n,a[100010]={0};
  int book[100100]={0};
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int sum=0;
  for(int i=n-1;i>0;i--)
  {
    for(int j=i-1;j>=0;j--)
    {
      if(book[j])continue;
      if(a[i]>a[j])
      {
        book[j]=1;
        sum++;
        break;
      }
    }
  }
  cout<<sum<<endl;
  //freopen("test.txt","r",stdin);
//  freopen("output.txt","w",stdout);
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define pi 3.1415926
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

const int INF=0x3f3f3f3f;
const int N=1e5+5;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
using namespace std;
int a[N];
int c[N];
int vis[N];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1,cmp);
    if(a[1]==a[n])
    {
        printf("0\n");
        return 0;
    }
    int cnt=0;
    for (int i=1;i<=n;i++)
    {
        bool flag=false;
        for (int j=i+1;j<=n;j++)
        {
            if(vis[j]) continue;
            if(a[i]>a[j]&&vis[j]==0)
            {
                cnt++;
                vis[j]=1;
                flag=true;
                break;
            }
        }
        if(!flag) break;
    }
    printf("%d\n",cnt);

}


#include<iostream>
#include<cstdio>
#include<fstream>
#include<set>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<iomanip>
#include<cstdlib>
#include<list>
#include<queue>
#include<stack>
#include<algorithm>
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define meminf(a) memset(a,inf,sizeof(a))
//vector ::iterator it;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n,a[100010]={0};
  int book[100100]={0};
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int sum=0;
  for(int i=n-1;i>0;i--)
  {
    bool flag=true;
    for(int j=i-1;j>=0;j--)
    {
      if(book[j])continue;
      if(a[i]>a[j])
      {
        book[j]=1;
        sum++;
        flag=false;
        break;
      }
    }
    if(flag)break;
  }
  cout<<sum<<endl;
  //freopen("test.txt","r",stdin);
//  freopen("output.txt","w",stdout);
}


#include<iostream>
#include<cstdio>
#include<fstream>
#include<set>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<iomanip>
#include<cstdlib>
#include<list>
#include<queue>
#include<stack>
#include<algorithm>
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define meminf(a) memset(a,inf,sizeof(a))
//vector ::iterator it;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(cin>>n)
  {
    int a[100100]={0};
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int t=a[0],sum=1;
    for(int i=1;i<n;i++)
    {
      if(a[i]==t)sum++;
      else break;
    }
    cout<<n-sum<<endl;
  }
  //freopen("test.txt","r",stdin);
//  freopen("output.txt","w",stdout);
}


#include <bits/stdc++.h>
using namespace std;
int n, v[100001], f[100001], p, ans, x = 1, y = 1;
int main(){
	scanf ( "%d", &n );
	for ( int i = 1; i <= n; i++ )
		scanf ( "%d", &v[i] );
	sort ( v + 1, v + n + 1 );
	for ( int i = 1; i <= n; i++ )
		f[i] = v[i];
	while ( x <= n && y <= n ){
		if ( v[x] >= f[y] )
			y++;
		else
			x++, y++, ans++;
	}
	printf ( "%d\n", ans );
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[100000];
bool tf[100000];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	int ans=0,t=0;
	for(int i=0;i<n;i++)
		for(t++;t<n;t++)
			if(a[t]>a[i] && !tf[t])
			{
				ans++;
				tf[t]=true;
				break;
			}
	printf("%d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,tot;
int a[105000];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int temp=2;
    while(a[temp]==a[temp-1]) temp++;
    for(int i=temp;i<=n;i++)
        if(a[i]>a[i-temp+1]) tot++;
    printf("%d",tot);
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,tot;
int a[105000];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int temp1=1,temp2=1;
    a[n+1]=-1;
    while(temp2<=n)
    {
        while(a[temp1]>=a[temp2]&&temp2<=n) temp2++;
        if(a[temp1]<a[temp2]) {tot++;temp1++;temp2++;}
    }
    printf("%d",tot);
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,tot;
int a[105000];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int temp=2;
    while(a[temp]==a[temp-1]) temp++;
    for(int i=temp;i<=n;i++)
        if(a[i]>a[i-temp+1]) tot++;
    printf("%d\n",tot);
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,tot;
int a[105000];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int temp1=1,temp2=1;
    while(temp2<=n)
    {
        while(a[temp1]>=a[temp2]) temp2++;
        if(a[temp1]<a[temp2]) {tot++;temp1++;temp2++;}
    }
    printf("%d",tot);
}


/*
 ********************************************************************************
 *       Filename:  shmpc.c
 *    Description:  IPC:share memory
 *
 *        Company:  Security Operation System Lesson
 *      Copyright:  Copyright (c) 2010, Peakzhao
 ********************************************************************************
 */

#include	<stdio.h>
#include	<stdlib.h>
#include	<unistd.h>

#include	<sys/ipc.h>
#include	<sys/shm.h>
#include	<sys/types.h>
#include	<sys/sem.h>
#include	"shmpc.h"

/*
 ********************************************************************************
 *         Name:  main
 *  Description:  entry point
 ********************************************************************************
 */

//var used to shared memory
int shmid;
void *myshm;
struct myshm_st *buf;

//var used to semaphore
int semid;

//common var
int i,n;

void producer()
{

	printf ( "Create a Producer Process Success,%d\n",getpid());

	//attach share memory
	myshm=shmat(shmid,NULL,0);
	if(myshm==(void *)-1)
	{
		perror("shmat");
		exit(-1);
	}

	buf=(struct myshm_st *)myshm;

	//produe a product
	for(n=0;n<NSIZE;n++)
	{
		while(buf->m_count==BUFSIZE)
		{
			printf("[%d/P/%d]:Blocked!\n",getpid(),n);
			sleep(5);
		}

		//P
		struct sembuf action;
		action.sem_num=0;
		action.sem_op=-1;
		action.sem_flg=SEM_UNDO;
		if(semop(semid,&action,1)==-1)
		{
			perror("semop");
			exit(0);
		}

		buf->m_count++;

		/*add sleep will create race condition of producers*/
		/*int tmp;*/
		/*tmp=buf->m_in;*/
		/*sleep(1);*/
		/*buf->m_buf[tmp]='A';*/
		/*tmp++;*/
		/*sleep(1);*/
		/*buf->m_in=tmp%BUFSIZE;*/

		buf->m_buf[buf->m_in]='A';
		sleep(1);
		buf->m_in=(buf->m_in+1)%BUFSIZE;

		printf("[%d/P/%d]:",getpid(),n);
		for(i=0;i<10;i++)
		{
			if(buf->m_buf[i]=='A')
				printf("|A");
			else
				printf("| ");
		}
		printf("|\n");

		//V
		action.sem_op=1;
		if(semop(semid,&action,1)==-1)
		{
			perror("semop");
			exit(0);
		}

		sleep(DELT);
	}
	if(shmdt(myshm)==-1)
		perror("shmdt");
	exit(0);
}

void consumer()
{

	printf ( "Create a Consumer Process Success,%d\n",getpid());

	//attach share memory
	myshm=shmat(shmid,NULL,0);
	if(myshm==(void *)-1)
	{
		perror("shmat");
		exit(-1);
	}

	buf=(struct myshm_st *)myshm;

	//consum a product
	for(n=0;n<NSIZE;n++)
	{
		while(buf->m_count==0)
		{
			printf("[%d/C/%d]:Blocked!\n",getpid(),n);
			sleep(5);
		}

		//P
		struct sembuf action;
		action.sem_num=0;
		action.sem_op=-1;//此时发生切换？
		action.sem_flg=SEM_UNDO;
		if(semop(semid,&action,1)==-1)
		{
			perror("semop");
			exit(0);
		}

		buf->m_count--;
		buf->m_buf[buf->m_out]=' ';
		buf->m_out=(buf->m_out+1)%BUFSIZE;

		printf("[%d/C/%d]:",getpid(),n);
		for(i=0;i<10;i++)
		{
			if(buf->m_buf[i]=='A')
				printf("|A");
			else
				printf("| ");
		}
		printf("|\n");

		//V
		action.sem_op=1;
		if(semop(semid,&action,1)==-1)
		{
			perror("semop");
			exit(0);
		}

		sleep(DELT);
	}
	if(shmdt(myshm)==-1)
		perror("shmdt");
	exit(0);

}

int main(int argc, char *argv[])
{

	char t;
	int ppid,cpid;

	//create a shared memery
	printf("Begin...\n");
	shmid=shmget(MYKEY,sizeof(struct myshm_st),IPC_CREAT|0770);
	if( shmid==-1 )
	{
		perror("shmget");
		exit(-1);
	}

	//attach shared memory
	myshm=shmat(shmid,NULL,0);
	if(myshm==(void *)-1)
	{
		perror("shmat");
		exit(-1);
	}

	//init shared memory
	buf=(struct myshm_st *)myshm;
	buf->m_count=0;
	buf->m_in=0;
	buf->m_out=0;

	//create a semaphore
	semid=semget(MYKEY,1,IPC_CREAT|IPC_EXCL|0770);
	if( semid==-1 )
	{
		perror("semget");
		exit(0);
	}

	union semun init_val;
	init_val.val=1;
	if( semctl(semid,0,SETVAL,init_val )==-1)
	{
		perror("semctl");
		exit(0);
	}

	for(;;)
	{
		t=getchar();
		switch ( t )
		{
			case 'p' :
				//create a producer process
				ppid=fork();
				if( ppid==0 )
				{
					producer();
				}
				break;
			case 'c':
				cpid=fork();
				if( cpid==0 )
				{
					consumer();
				}
				break;
			case 's':
				//please add stat code here
			case 'q':
				if(shmdt(myshm)==-1)
					perror("shmdt");
				if(shmctl(shmid,IPC_RMID,0)==-1)
					perror("shmctl");
				if(semctl(semid,1,IPC_RMID,NULL)==-1)
					perror("semctl");
				exit(0);
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef long long ll;
int a[100010];
bool b[100010];
int main()
{
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//    #endif // ONLINE_JUDGE
//
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    //memset(b,0,sizeof(b));
    int ans(0);
    int j=1;
    for(int i=0;i<n;i++){
        while(a[i]==a[j] && j<n)j++;
        if(j==n)break;
        ans++;
        j++;
    }

    cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef long long ll;
vector<int> a,b;
int main()
{
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//    #endif // ONLINE_JUDGE
//
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        a.push_back(x);
        b.push_back(x);
    }
    sort(b.begin(),b.end());
    vector<int>::iterator it;
    int ans(0);
    for(int i=0;i<n;i++){
        it=lower_bound(b.begin(),b.end(),a[i]+1);
        if(it!=b.end()){
            ans++;
            b.erase(it);
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef long long ll;
int a[100010];
bool b[100010];
int main()
{
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//    #endif // ONLINE_JUDGE
//
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    memset(b,0,sizeof(b));
    int ans(0);
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
          if(a[i]>a[j] && b[j]==0){
                ans++;
                b[j]=1;
                break;
          }
    cout<<ans<<"\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}
	int ans=0,p=2;
	for(i=1;i<=j;){
		if(b[p]==0)p++;
		if(c[i]==0)i++;
		if(p==i)p++;
		if(p>j)goto A;
		b[p]--;c[i]--;ans++;
	}
	A:;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}
	//int count=0,ans=0;
	/*for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}*/
	//int ans=n-b[1];
	//if(j==1)ans=0;
	int ans=0;int p=2;
	for(i=1;i<j;i++){
		while(c[i]>0){
			b[p]--;c[i]--;ans++;
			//printf("%d %d\n",i,p);
			if(b[p]==0)p++;
			if(p>j)goto A;
		}
	}
	A:;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}
	int ans=0;p=2;
	for(i=1;i<=j;){
		if(b[p]==0)p++;
		if(c[i]==0)i++;
		if(p==i)p++;
		if(p>j)goto A;
		b[p]--;c[i]--;ans++;
	}
	A:;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005]={};
	//int b[100005]={};
	//int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	//int last=0,j=0;
	/*for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}*/
	//int count=0,ans=0;
	/*for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}*/
	//int ans=n-b[1];
	//if(j==1)ans=0;
	/*int ans=0;int p=2;
	for(i=1;i<j;i++){
		while(c[i]>0){
			if(p>j)goto A;
			b[p]--;c[i]--;ans++;
			//printf("%d %d\n",i,p);
			if(b[p]==0)p++;

		}
	}*/
	int j=n;
	for(i=1;i<n;i++){
		if(a[i+1]>a[i]){
			j=i+1;
			break;
		}
	}
	int ans=0;
	for(i=j;i<=n;i++){
		if(a[i]>a[i-j+1])ans++;
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
	}
	int count=0,ans=0;
	for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}
	ans=max(ans,1);
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	//int b[100005]={};
	//int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	//int last=0,j=0;
	/*for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}*/
	//int count=0,ans=0;
	/*for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}*/
	//int ans=n-b[1];
	//if(j==1)ans=0;
	/*int ans=0;int p=2;
	for(i=1;i<j;i++){
		while(c[i]>0){
			if(p>j)goto A;
			b[p]--;c[i]--;ans++;
			//printf("%d %d\n",i,p);
			if(b[p]==0)p++;

		}
	}*/
	int j;
	for(i=1;i<n;i++){
		if(a[i+1]>a[i]){
			j=i+1;
			break;
		}
	}
	int ans=0;
	for(i=j;i<=n;i++){
		if(a[i]>a[i-j+1])ans++;
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
	}
	int count=0,ans=0;
	for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}
	ans=max(ans,1);
	if(j==1)ans=0;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}
	//int count=0,ans=0;
	/*for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}*/
	//int ans=n-b[1];
	//if(j==1)ans=0;
	int ans=0;
	c[1]=0;int p=1;
	for(i=2;i<=n;i++){
		while(c[i]>0){
			c[i]--;c[p]++;ans++;
			if(c[p]==b[p])p++;
			if(p==i)goto A;
		}
		A:;
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 0x3f3f3f3f

int main(){
	int n;
	scanf("%d",&n);
	int i;
	int a[100005];
	int b[100005]={};
	int c[100005]={};
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int last=0,j=0;
	for(i=1;i<=n;i++){
		if(a[i]>last){
			j++;last=a[i];
		}
		b[j]++;
		c[j]++;
	}
	//int count=0,ans=0;
	/*for(i=1;i<=j;i++){
		//printf("%d\n",b[i]);
		count+=b[i];
		if( count <= (int)(n/2.0+0.5) ){
			ans=count;
		}
		if( count >= (int)(n/2.0+0.5) ){
			break;
		}
	}*/
	//int ans=n-b[1];
	//if(j==1)ans=0;
	int ans=0;int p=2;
	for(i=1;i<j;i++){
		while(c[i]>0){
			if(p>j)goto A;
			b[p]--;c[i]--;ans++;
			//printf("%d %d\n",i,p);
			if(b[p]==0)p++;

		}
	}
	A:;
	printf("%d\n",ans);
	return 0;
}


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

int n,a[100001];
vector <int> b;

bool cmp(int a, int b){
    return a<b;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    /*int cnt=1;
    for(int i=n-2;i>=0;i--){
        if(a[i]==a[i+1]){cnt++;}else{
            b.push_back(cnt);
            cnt=1;
        }
    }
    b.push_back(cnt);
    //for(int i=0;i<b.size();i++)cout<<b[i]<<" ";
    //cout<<endl;
    int ans=0,s=0;
    for(int i=0;i<b.size()-1;i++){
        s+=b[i];
        //cout<<s<<" "<<endl;
        if(s>b[i]){
            ans+=b[i];
        }
        else{
            ans+=s;
            s=b[i];
        }
    }
    cout<<ans;*/
    int ans=0;
    int i=0,j=0;
    while(i<n && j<n){
        while(j<n && a[j]<=a[i])j++;
        if(j<n) ans++;
        i++;j++;
    }
    cout<<ans;
}


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

int n,a[100001],c[100001];
vector <int> b;

bool cmp(int a, int b){
    return a<b;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    /*int cnt=1;
    for(int i=n-2;i>=0;i--){
        if(a[i]==a[i+1]){cnt++;}else{
            b.push_back(cnt);
            cnt=1;
        }
    }
    b.push_back(cnt);
    //for(int i=0;i<b.size();i++)cout<<b[i]<<" ";
    //cout<<endl;
    int ans=0,s=0;
    for(int i=0;i<b.size()-1;i++){
        s+=b[i];
        //cout<<s<<" "<<endl;
        if(s>b[i]){
            ans+=b[i];
        }
        else{
            ans+=s;
            s=b[i];
        }
    }
    cout<<ans;*/
    int i;
    int ans=0;
    int mn=a[0];
    for(int i=0;i<n;i++)c[i]=a[i];
    for(i=1;i<n;i++){
        if(a[i]!=a[i-1])break;
    }
    for(int j=i;j<n;j++){
        a[j-i] = a[j];
    }
    for(int j=n-i;j<n;j++){a[j]=mn;}
    //for(i=0;i<n;i++)cout<<a[i]<<" ";
    //cout<<endl;
    for(i=0;i<n;i++){
        if(a[i]>c[i])ans++;
    }
    cout<<ans;
}


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

int n,a[100001];
vector <int> b;

bool cmp(int a, int b){
    return a<b;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    int cnt=1;
    for(int i=n-2;i>=0;i--){
        if(a[i]==a[i+1]){cnt++;}else{
            b.push_back(cnt);
            cnt=1;
        }
    }
    b.push_back(cnt);
    //for(int i=0;i<b.size();i++)cout<<b[i]<<" ";
    //cout<<endl;
    int ans=0,s=0;
    for(int i=0;i<b.size()-1;i++){
        s+=b[i];
        //cout<<s<<" "<<endl;
        ans+=min(s,b[i-1]);
    }
    cout<<ans;
}


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

int n,a[100001],c[100001];
vector <int> b;

bool cmp(int a, int b){
    return a<b;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    /*int cnt=1;
    for(int i=n-2;i>=0;i--){
        if(a[i]==a[i+1]){cnt++;}else{
            b.push_back(cnt);
            cnt=1;
        }
    }
    b.push_back(cnt);
    //for(int i=0;i<b.size();i++)cout<<b[i]<<" ";
    //cout<<endl;
    int ans=0,s=0;
    for(int i=0;i<b.size()-1;i++){
        s+=b[i];
        //cout<<s<<" "<<endl;
        if(s>b[i]){
            ans+=b[i];
        }
        else{
            ans+=s;
            s=b[i];
        }
    }
    cout<<ans;*/
    int i;
    int ans=0;
    for(int i=0;i<n;i++)c[i]=a[i];
    for(i=1;i<n;i++){
        if(a[i]!=a[i-1])break;
    }
    for(int j=i;j<n;j++){
        a[j-i] = a[j];
    }
    for(i=0;i<n;i++){
        if(a[i]>c[i])ans++;
    }
    cout<<ans;
}


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

int n,a[100001];
vector <int> b;

bool cmp(int a, int b){
    return a<b;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,cmp);
    int cnt=1;
    for(int i=n-2;i>=0;i--){
        if(a[i]==a[i+1]){cnt++;}else{
            b.push_back(cnt);
            cnt=1;
        }
    }
    b.push_back(cnt);
    //for(int i=0;i<b.size();i++)cout<<b[i]<<" ";
    //cout<<endl;
    int ans=0,s=0;
    for(int i=0;i<b.size()-1;i++){
        s+=b[i];
        //cout<<s<<" "<<endl;
        if(s>b[i]){
            ans+=b[i];
        }
        else{
            ans+=s;
            s=b[i];
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

ifstream fin ("in.in");

int N;
vector < int > v, x;

int main()
{
    cin >> N;
int k;
    for (int i = 1; i <= N; ++i)
    {
        cin >> k;
        //v.push_back(k);
        x.push_back(k);
    }

sort(x.begin(), x.end());

int a=0, b=1, act = 0;

while (b < N)
{
    if (x[a] < x[b]) act++, b++, a++;
    else b ++;
}
cout << act;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

ifstream fin ("in.in");

int N;
vector < int > v, x;

int main()
{
    cin >> N;
int k;
    for (int i = 1; i <= N; ++i)
    {
        cin >> k;
        v.push_back(k);
        x.push_back(k);
    }

    int maxx = 0, act = 0;

sort(x.begin(), x.end());
sort(v.begin(), v.end());

do
    {
        act = 0;
        for (int i = 0; i < N; ++i)
            {if (x[i] > v[i]) act ++;
            //cout << x[i] << " ";
            }
            //cout << endl;
        maxx = max(maxx, act);
    }    while (next_permutation(x.begin(), x.end()));
    cout << maxx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

ifstream fin ("in.in");

int N;
vector < int > v, x;

int main()
{
    cin >> N;
int k;
    for (int i = 1; i <= N; ++i)
    {
        cin >> k;
        v.push_back(k);
        x.push_back(k);
    }

    int maxx = 0, act = 0;

sort(x.begin(), x.end());
sort(v.begin(), v.end());

do
    {
        act = 0;
        for (int i = 1; i <= N; ++i)
            {if (x[i] > v[i]) act ++;
            //cout << x[i] << " ";
            }
            //cout << endl;
        maxx = max(maxx, act);
    }    while (next_permutation(x.begin(), x.end()));
    cout << maxx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

ifstream fin ("in.in");

int N;
vector < int > v, x;

int main()
{
    cin >> N;
int k;
    for (int i = 1; i <= N; ++i)
    {
        cin >> k;
        //v.push_back(k);
        x.push_back(k);
    }

sort(x.begin(), x.end());

int a=0, b=1, act = 0;

while (b <= N)
{
    if (x[a] < x[b]) act++, b++, a++;
    else b ++;
}
cout << act;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

ifstream fin ("in.in");

int N;
vector < int > v, x;

int main()
{
    cin >> N;
int k;
    for (int i = 1; i <= N; ++i)
    {
        cin >> k;
        v.push_back(k);
        x.push_back(k);
    }

    int maxx = 0, act = 0;

do
    {
        act = 0;
        for (int i = 1; i <= N; ++i)
            if (x[i] > v[i]) act ++;
        maxx = max(maxx, act);
    }    while (next_permutation(x.begin(), x.end()));
    cout << maxx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

ifstream fin ("in.in");

int mat[3][100005];
int N;
vector < int > v, x;

int main()
{
    cin >> N;
int k;
    for (int i =1; i<=N; ++i)
    {
        cin >> k;
        v.push_back(k);
        x.push_back(k);
    }

    int maxx = 0, act = 0;

    while (next_permutation(x.begin(), x.end()))
    {
        act =0;
        for (int i =1; i<=N; ++i)
            if (x[i] > v[i]) act ++;
        maxx = max(maxx, act);
    }
    cout << maxx;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
vector<int> a,b;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int m;
		scanf("%d",&m);
		a.push_back(m);
		b.push_back(m);
	}
	int ans=0;
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
	{
		vector<int> ::iterator it=lower_bound(a.begin(),a.end(),b[i]+1);
		if(it!=a.end())
		{
			ans++;
			b.erase(it);
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
vector<int> a,b;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int m;
		scanf("%d",&m);
		a.push_back(m);
		b.push_back(m);
	}
	int ans=0;
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
	{
		vector<int> ::iterator it=lower_bound(a.begin(),a.end(),b[i]+1);
		if(it!=a.end())
		{
			ans++;
			a.erase(it);
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf 0x7f7f7f7f
#define N 100001

int in[N];

int main(){
    int n, curr;
    int ans = 0;
    cin >> n;
    for (int i = 0; i < n;i++){
        scanf("%d", &in[i]);
    }
    sort(in, in + n);
    curr = n - 1;
    for (int i = n - 1; i >= 0; i--){
        int tmp = in[i];
        for (int j = curr; j >= 0;j--)
            if(in[j]<tmp){
                curr = j;
                ans++;
                break;
            }
        if(curr<0)
            break;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf 0x7f7f7f7f
#define N 100001

int in[N];

int main()
{
    int n, curr;
    int ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &in[i]);
    }
    sort(in, in + n);
    curr = n - 2;
    for (int i = n - 1; i >= 0; i--)
    {
        int tmp = in[i];
        for (int j=curr; j >= 0; j--){
            curr = j;
            if (in[j] < tmp)
            {
                curr =j-1 ;
                ans++;
                break;
            }
        }
        if (curr < 0)
            break;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf 0x7f7f7f7f
#define N 100001

int in[N];

int main(){
    int n, curr;
    int ans = 0;
    cin >> n;
    for (int i = 0; i < n;i++){
        scanf("%d", &in[i]);
    }
    sort(in, in + n);
    curr = n - 2;
    for (int i = n - 1; i >= 0; i--){
        int tmp = in[i];
        for (int j = curr; j >= 0;j--)
            if(in[j]<tmp){
                curr = j-1;
                ans++;
                break;
            }
        if(curr<0)
            break;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int a[10005];
int main(void){
    int n;

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a,a + n);
    int num = 0;
    for(int i = 0;i < n;i++){
        if(a[i] > a[num]) num++;
    }
    cout << num << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int a[100005];
int main(void){
    int n;

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a,a + n);
    int num = 0;
    for(int i = 0;i < n;i++){
        if(a[i] > a[num]) num++;
    }
    cout << num << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
typedef long long ll ;
using namespace std ;

int main()
{
	int n ;
	cin >> n ;
	ll ar[100001] ;
	for(int i=0 ; i<n ; i++)
		cin >> ar[i] ;
	sort(ar,ar+n) ;
	int cnt=0 ;
	int j=1 ;
	int t = 1 ;
	for(int i=0 ; i<n-1 ; i++)
	{
	    if(ar[i]==ar[i+1])
	    {
	    	j++ ;
	    	t++ ;
	    	continue ;
		}
		if(n-j<=t)
		{
			cnt += n-j ;
			break ;
		}
		else
		{
			cnt += t ;
			j += t ;
		}
		t = 1 ;
	}
	cout << cnt << endl ;
	return 0 ;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
typedef long long ll ;
using namespace std ;

int main()
{
	int n ;
	cin >> n ;
	ll ar[100001] ;
	for(int i=0 ; i<n ; i++)
		cin >> ar[i] ;
	sort(ar,ar+n) ;
	int cnt=0 ;
	int j=1 ;
	int t = 1 ;
	for(int i=0 ; i<n-1 ; i++)
	{
	    while(ar[j]==ar[i])
	    {
	    	t++ ;
	    	j++ ;
	    }
	    if(j==n) break ;
	    j += t ;
	    cnt += t ;
	    t = 1 ;
	    //cout << cnt << " " << i << " " << j << endl ;
	}
	cout << cnt << endl ;
	return 0 ;
}


#include <iostream>
#include <algorithm>
typedef long long ll ;
using namespace std ;

int main()
{
	int n ;
	cin >> n ;
	ll ar[10001] ;
	for(int i=0 ; i<n ; i++)
		cin >> ar[i] ;
	sort(ar,ar+n) ;
	int cnt=0 ;
	int j=1 ;
	for(int i=0 ; i<n-1 ; i++)
	{
	    while(ar[j]==ar[i])
	    	j++ ;
	    if(j==n) break ;
	    j++ ;
	    cnt++ ;
	    //cout << cnt << " " << i << " " << j << endl ;
	}
	cout << cnt << endl ;
	return 0 ;
}


#include <iostream>
#include <algorithm>
typedef long long ll ;
using namespace std ;

int main()
{
	int n ;
	cin >> n ;
	ll ar[100001] ;
	for(int i=0 ; i<n ; i++)
		cin >> ar[i] ;
	sort(ar,ar+n) ;
	int cnt=0 ;
	int j=1 ;
	for(int i=0 ; i<n-1 ; i++)
	{
	    while(ar[j]==ar[i])
	    	j++ ;
	    if(j==n) break ;
	    j++ ;
	    cnt++ ;
	    //cout << cnt << " " << i << " " << j << endl ;
	}
	cout << cnt << endl ;
	return 0 ;
}


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

ll ara1[100001];
bool detect[100001];
int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(!detect[i] && ara[i] == ara[i-1] && i != n-1){
            ara1[i+1] = ara1[i];
            //cout<<ara1[i+1]<<' '<<i<<endl;
        }
        if(ara1[i] > 0){
            c++;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                detect[i+1] = 1;
                //cout<<ara1[i+1]<<' '<<i<<endl;
            }
        }
    }

    printf("%d\n", c);
}


#include<bits/stdc++.h>
using namespace std;
bool func(int a, int b)
{
    return a > b;
}
int main()
{
    int n, ara[100001], ara1[100001];
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &ara[i]);
        ara1[i] = ara[i];
    }
    sort(ara1, ara1+n);
    sort(ara, ara+n, func);
    //    for(int i = 0; i < n; i++){
    //        cout<<ara[i]<<' ';
    //    }
    //    cout<<endl;
    int c = 0;
    for(int i = 0; i < n; i++){
        if(ara[i] > ara1[i]){
            c++;
        }
        else if(ara[i+1] < ara[i] && i != n-1){
            c++;
        }
    }
    printf("%d\n", c);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ara1[100001];

int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(ara1[i] > 0){
            c++;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                //cout<<ara1[i+1]<<' '<<i<<endl;
            }
        }
    }

    printf("%d\n", c);
}


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

ll ara1[100001];
bool detect[100001];
int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(!detect[i] && ara[i] == ara[i-1] && i != n-1){
            ara1[i] = ara1[i-1] - 1;
            //cout<<ara1[i+1]<<' '<<i<<endl;
        }
        if(ara1[i] > 0){
            c++;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                detect[i+1] = 1;
                //cout<<ara1[i+1]<<' '<<i<<endl;
            }
        }
    }

    printf("%d\n", c);
}


#include<bits/stdc++.h>
using namespace std;
bool func(int a, int b)
{
    return a > b;
}
int main()
{
    int n, ara[100001], ara1[100001];
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &ara[i]);
        ara1[i] = ara[i];
    }
    sort(ara1, ara1+n);
    sort(ara, ara+n, func);
    //    for(int i = 0; i < n; i++){
    //        cout<<ara[i]<<' ';
    //    }
    //    cout<<endl;
    int c = 0;
    for(int i = 0; i < n; i++){
        if(ara[i] > ara1[i]){
            c++;
        }
    }
    printf("%d\n", c);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ara1[100001];

int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(ara1[i] > 0){
            c++;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                cout<<ara1[i+1]<<' '<<i<<endl;
            }
        }
    }

    printf("%d\n", c);
}


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

ll ara1[100001];
bool detect[100001];
int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;
//    for(int i = 0; i < n; i++){
//        cout<<ara[i]<<' ';
//    }
//    cout<<endl;
    int d = 0;
    for(int i = 1; i < n; i++){
        if(ara[d] < ara[i]){
            c++;
            d++;
        }
    }

    printf("%d\n", c);
}


#include<bits/stdc++.h>
using namespace std;
bool func(int a, int b)
{
    return a > b;
}
int ara1[100001];
int main()
{
    int n, ara[100001], ara1[100001];
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &ara[i]);
    }
    sort(ara, ara+n);
        int e = 0;

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;
//    for(int i = 0; i < n; i++){
//            cout<<ara[i]<<' ';
//        }
//        cout<<endl;
//        for(int i = 0; i < n; i++){
//            cout<<ara1[i]<<' ';
//        }
//        cout<<endl;
    for(int i = 0; i < n; i++){
        if(ara1[i] > 0){
            c++;
        }
    }

    printf("%d\n", c);
}


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

ll ara1[100001];
bool detect[100001];
int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(!detect[i] && ara[i] == ara[i-1]){
            ara1[i] = ara1[i-1] - 1;
            //cout<<ara1[i+1]<<' '<<i<<endl;
        }
        if(ara1[i] > 0){
            c++;
            //cout<<ara1[i+1]<<' '<<i<<endl;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                detect[i+1] = 1;
            }
        }
    }

    printf("%d\n", c);
}


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

ll ara1[100001];
bool detect[100001];
int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(!detect[i] && ara[i] == ara[i-1] && i != n-1){
            ara1[i] = ara1[i-1];
            //cout<<ara1[i+1]<<' '<<i<<endl;
        }
        if(ara1[i] > 0){
            c++;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                detect[i+1] = 1;
                //cout<<ara1[i+1]<<' '<<i<<endl;
            }
        }
    }

    printf("%d\n", c);
}


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

ll ara1[100001];

int main()
{
    ll n, ara[100001];
    scanf("%I64d", &n);

    for(int i = 0; i < n; i++){
        scanf("%I64d", &ara[i]);
    }

    sort(ara, ara+n);

    for(int i = 1; i < n; i++){
        if(ara[i] > ara[i-1]){
            ara1[i] = i;
        }
        else{
            ara1[i] = ara1[i-1];
        }
    }

    int c = 0;

    for(int i = 1; i < n; i++){
        if(ara[i+1] == ara[i] && i != n-1){
            ara1[i+1] = ara1[i];
            //cout<<ara1[i+1]<<' '<<i<<endl;
        }
        if(ara1[i] > 0){
            c++;
            if(ara[i+1] == ara[i] && i != n-1){
                (ara1[i+1]) = ara1[i] - 1;
                //cout<<ara1[i+1]<<' '<<i<<endl;
            }
        }
    }

    printf("%d\n", c);
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
//#pragma GCC optimize(4)
using namespace std;
const int maxn = int(1e5) + 7;
int a[maxn], n, r = 1, ans;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(b + 1, b + 1 + n);
	for (int i = 1; i <= n; i++) {
		while (r <= n && a[r] <= a[i]) r++;
		if (r <= n) ans++, r++;
	}
	cout << ans << endl;
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
//#pragma GCC optimize(4)
using namespace std;
const int maxn = int(1e5) + 7;
int a[maxn], b[maxn], n, r = 1, ans;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(b + 1, b + 1 + n);
	for (int i = 1; i <= n; i++) {
		while (r <= n && a[r] <= a[i]) r++;
		if (r <= n) ans++, r++;
	}
	cout << ans << endl;
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
//#pragma GCC optimize(4)
using namespace std;
int n;
int a[100100];
int c[100100];
int judge(int l,int r,int x) {
	int mid=(l+r)>>1;
	if(l==r&&a[r]<x&&!c[r]) return l;
	else if(l+1==r&&a[r]<x&&!c[r])return r;
	else if(l+1==r&&a[l]<x&&!c[l])return l;
	else if(l+1==r) return -1;
	else if(l==r) return -1;
	if(a[mid]==x||c[mid]) return judge(l,mid-1,x);
	else return judge(mid,r,x);
}

int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	int ans=0;
	sort(a+1,a+1+n);
	for(int i=n; i>=2; i--) {
		int tmp=judge(1,i-1,a[i]);
		if(tmp==-1) break;
		c[tmp]=1;
		ans++;
	}
	printf("%d",ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <map>

using namespace std;

map<int, int> m;
map<int, int>::iterator it;

int main()
{
    int n, i, j, a, current, disponibles, permutations, maximal;

    scanf("%d", &n);
    for(i = 0; i < n; ++i){
        scanf("%d", &a);
        ++m[a];
    }

    it = m.begin();
    disponibles = (*it).second;
    maximal = 0;
    for(++it; it != m.end(); ++it){
        current = (*it).second;

        permutations = min(disponibles, current);
        maximal += permutations;

        current -= permutations;
        disponibles += current;
    }

    printf("%d", maximal);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <map>

using namespace std;

map<int, int> m;
map<int, int>::iterator it;

int main()
{
    int n, i, j, a, menores, maximal;

    scanf("%d", &n);
    for(i = 0; i < n; ++i){
        scanf("%d", &a);
        ++m[a];
    }

    it = m.begin();
    menores = (*it).second;
    maximal = 0;
    for(++it; it != m.end(); ++it)
        maximal += min(menores, (*it).second);

    printf("%d", maximal);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <map>

using namespace std;

map<int, int> m;
map<int, int>::iterator it;

int main()
{
    int n, i, j, a, menores, maximal;

    scanf("%d", &n);
    for(i = 0; i < n; ++i){
        scanf("%d", &a);
        ++m[a];
    }

    it = m.begin();
    menores = (*it).second;
    maximal = 0;
    for(++it; it != m.end(); ++it){
        maximal += min(menores, (*it).second);
        menores += (*it).second;
    }

    printf("%d", maximal);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int n;

int judge(int x)
{
    int num=0;
    int r=n-1,l=n-2;
    while(l>=0){
        if(a[r]>a[l]){
            r--;num++;l=r-1;
        }
        else {
            l--;
        }
        //cout<<r<<" "<<l<<" "<<num<<endl;
        if(num==x)break;
    }
    //cout<<x<<" "<<num<<endl;
    if(num>=x)return 1;
    else return 0;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    int ans=0;
    int l=0,r=n;
    while(l<=r){
        int mid=(l+r)/2;
        if(judge(mid))l=mid+1,ans=mid;
        else r=mid-1;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn],vis[maxn];
int n;

int judge()
{
    //memset(vis,0,sizeof vis);
    int num=0;
    int r=n-1,l=n-2;
    while(l>=0){
        if(a[r]>a[l] && vis[l]==0){
            vis[l]=1;
            r--;num++;l=r-1;
        }
        else {
            l--;
        }
        //cout<<r<<" "<<l<<" "<<num<<endl;
    }
    //cout<<x<<" "<<num<<endl;
    return num;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    printf("%d\n",judge());
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn],vis[maxn];
int n;

int judge(int x)
{
    memset(vis,0,sizeof vis);
    int num=0;
    int r=n-1,l=n-2;
    while(l>=0){
        if(a[r]>a[l] && vis[l]==0){
            vis[l]=1;
            r--;num++;l=r-1;
        }
        else {
            l--;
        }
        //cout<<r<<" "<<l<<" "<<num<<endl;
        if(num==x)break;
    }
    //cout<<x<<" "<<num<<endl;
    if(num>=x)return 1;
    else return 0;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    int ans=0;
    int l=0,r=n;
    while(l<=r){
        int mid=(l+r)/2;
        if(judge(mid))l=mid+1,ans=mid;
        else r=mid-1;
    }
    printf("%d\n",ans);
}


#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int *a=new int[n];
    map<int,int> mmap;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mmap.count(a[i])==0)
            mmap[a[i]]=1;
        else
            mmap[a[i]]++;
    }
    int total=0;
    for(int i=0;i<n;i++)
        for(map<int,int>::iterator it=mmap.begin();it!=mmap.end();it++)
        if(it->first>a[i])
        {
            total++;
            it->second--;
            if(it->second<=0)
                mmap.erase(it);
            break;
        }
    cout<<total<<endl;
}


#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int *a=new int[n];
    map<int,int> mmap;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(mmap.count(a[i])==0)
            mmap[a[i]]=1;
        else
            mmap[a[i]]++;
    }
    map<int,int> pos;
    int* pp=new int[n];
    int t=0;
    for(map<int,int>::iterator it=mmap.begin();it!=mmap.end();it++)
        {
            pos[it->first]=t;
            pp[t]=it->second;
            t++;

        }
    int total=0;
    /*for(int i=0;i<n;i++)
    {
        int t=pos[a[i]];
        map<int,int>::iterator iit=(mmap.begin());
        for(map<int,int>::iterator it=iit+t;it!=mmap.end();it++)
        if(it->first>a[i])
        {
            total++;
            it->second--;
            if(it->second<=0)
                mmap.erase(it);
            break;
        }
    }*/
    for(int i=0;i<n;i++)
    {
        int t=pos[a[i]];
        for(int j=t+1;j<pos.size();j++)
            if(pp[j]>0)
        {
            total++;
            pp[j]--;
            break;
        }
    }

    cout<<total<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* a = new int[n];
	bool* b = new bool[n];
	int* c = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		c[i] = a[i];
		b[i] = true;
	}
	sort(c,c+n);
	int total = 0;
	for (int i = 0; i < n; i++)
	{
		int mid ;
		int l = 0, r = n;
		while (l <= r)
		{
			mid = (l+r) / 2;
			if (c[mid] == a[i])
				break;
			else if (c[mid] > a[i])
				r = mid - 1;
			else
				l = mid + 1;
		}
		int j = 0;
		for (j = mid+1; j < n;j++)
			if (c[j]>a[i]&&b[j] == true)
			{
				total++;
				b[j] = false;
				break;
			}
		if (j >= n)
			for (int k = 0; k < n;k++)
				if (b[k] == true)
				{
					b[j] = false;
					break;
				}
	}
	cout << total << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long int c=0;
	for(i=0;i<=n/2;i++)
	{
		if(a[i]<a[n/2+i])
		{
			c++;
		}
	}
	cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,j;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long int c=0;
	for(i=0;i<n-1;i++)
	{
		if(a[i+1]!=a[i])
		{
			i=i;
			break;
		}
	}
	i++;
	for(j=i;j<n;j++)
	{
		if(a[j]>a[j-i])
		c++;
		else
		break;
	}
	cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,j,k;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long int c=0;
	for(i=0;i<n-1;i++)
	{
		if(a[i+1]!=a[i])
		{
			i=i;
			break;
		}
	}
	j=i++;
	k=0;
	while(j<n)
	{
		if(a[j]>a[k])
		{
			c++;
			j++;
			k++;
		}
		else
		{
			j++;
		}
	}
	cout<<c;
	return(0);

	for(j=i;j<n;j++)
	{
		if(a[j]>a[j-i])
		c++;
	}
	cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,j;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long int c=0;
	for(i=0;i<n-1;i++)
	{
		if(a[i+1]!=a[i])
		{
			i=i;
			break;
		}
	}
	i++;
	for(j=i;j<n;j++)
	{
		if(a[j]>a[j-i])
		c++;
	}
	cout<<c;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
using namespace std;
int n,x,maxn;
map<int,int> a;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {scanf("%d",&x); maxn=max(maxn,++a[x]);}
	printf("%d",n-maxn);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n,a[100010],topt,num[100010],numnow[100010],ans;
bool cmp(int aa,int bb){return aa>bb;}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++)
	 if (a[i]!=a[i-1]) num[topt]=n-i+1,numnow[++topt]=1;else numnow[topt]++;
	for (int i=1;i<=topt-1;i++)
	 if (numnow[i]<num[i]) ans+=numnow[i];
	  else {ans+=num[i]; break;}
	printf("%d",ans);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
int n,a[100010],topt,num[100010],numnow[100010],ans;
bool cmp(int aa,int bb){return aa>bb;}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++)
	 if (a[i]!=a[i-1]) num[topt]=n-i+1,numnow[++topt]=1;else numnow[topt]++;
	for (int i=1;i<=topt-1;i++)
	 ans+=min(num[i],numnow[i]);
	printf("%d",ans);
return 0;
}


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

using namespace std ;

const int MAXN=2e5+100;

int a[MAXN];
int n ;
int res ;

int main ()
{
	int i , j ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) scanf("%d",a+i);
	sort(a+1,a+n+1);
	for ( i=1 , j=1 ; i<=n && j<=n ; i++,j++ )
	{
		while ( a[i]==a[j] ) j++;
		if ( j>n ) break;
		res++;
	}
	printf("%d\n",res);
	return 0 ;
}


import java.util.*;
import java.io.*;

public class JavaApp2 {

    public static void main(String[] args)   {

Scanner sc = new Scanner(System.in);

boolean flag = true;
int count = Integer.parseInt(sc.nextLine());
String arraylines[] = new String[count];
ArrayList<String> lines = new ArrayList<String>(count);

for (int i = count-1; i>=0; i--)
    arraylines[i] = sc.nextLine();

for (int i = 0;i<=(count-1);i++)
      lines.add(i , arraylines[i]);

int j = 0;
 for (int i =(j+1) ; i <= count-1; i++)
 {
     if (lines.get(j).equals( lines.get(i) ) )
        {
            lines.remove(i);
            i--;
            count--;
        }
       if (i== (count-1) ) {

           i=++j;

       }
 }

 for (int i = 0;i<=(count-1);i++)
      System.out.println(lines.get(i));

}

}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        List<String> s = new ArrayList<>();
        Map<String, Integer> f = new TreeMap<>();
        int n = in.nextInt();
        for (int i = 0; i < n; i++){
            s.add(in.next());
        }

        int top = 1;
        for (int i = n - 1; i >= 0; i--){
            if (!f.containsKey(s.get(i))){
                f.put(s.get(i), top++);
            }
        }

        Map<Integer, String> m = new TreeMap<>();

        for (Map.Entry<String, Integer> i: f.entrySet()) {
            m.put(i.getValue(), i.getKey());
        }

        for (Map.Entry<Integer, String> i: m.entrySet()) {
            System.out.println(i.getValue());
        }
    }
}


import com.sun.xml.internal.bind.v2.util.QNameMap;

import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        List<String> s = new ArrayList<>();
        Map<String, Integer> f = new TreeMap<>();
        int n = in.nextInt();
        for (int i = 0; i < n; i++){
            s.add(in.next());
        }

        int top = 1;
        for (int i = n - 1; i >= 0; i--){
            if (!f.containsKey(s.get(i))){
                f.put(s.get(i), top++);
            }
        }

        Map<Integer, String> m = new TreeMap<>();

        for (Map.Entry<String, Integer> i: f.entrySet()) {
            m.put(i.getValue(), i.getKey());
        }

        for (Map.Entry<Integer, String> i: m.entrySet()) {
            System.out.println(i.getValue());
        }
    }
}


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
import java.util.Vector;

/**
 *
 * @author Morshed
 */
public class JavaApplication29 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Vector<String> v=new Vector();
        Map<String,Integer> map=new HashMap<String,Integer>();
        int n=sc.nextInt();
        String s;
        for(int i=0;i<n;i++){
            s=sc.next();
            v.add(s);
            map.put(s, 0);
        }
        for(int i=v.size()-1;i>=0;i--){
            if(map.get(v.get(i))==1){
                continue;
            }
            else{
                System.out.println(v.get(i));
                map.put(v.get(i), 1);
            }
        }
    }

}


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

/**
 *
 * @author Morshed
 */
public class JavaApplication29 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Stack<String> st=new Stack();
        int n=sc.nextInt();
        String s;
        for(int i=0;i<n;i++){
            s=sc.next();
            if(st.contains(s)){
                st.remove(s);
                st.add(s);
            }
            else{
                st.add(s);
            }
        }
        Iterator it=st.iterator();
        while(it.hasNext()){
            String s2=st.peek();
            st.pop();
            System.out.println(s2);
        }
    }

}


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

/**
 *
 * @author Morshed
 */
public class JavaApplication29 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Stack<String> st=new Stack();
        int n=sc.nextInt();
        String s;
        for(int i=0;i<n;i++){
            s=sc.next();
            if(st.contains(s)){
                st.remove(s);
                st.add(s);
            }
            else{
                st.add(s);
            }
        }
        Iterator it=st.iterator();
        while(it.hasNext()){
            System.out.println(st.pop());
        }
    }

}


import java.io.*;
import java.util.*;
public class da {
    public static void main(String args[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = sc.nextInt();
        Stack<String> order = new Stack<>();
        for (int i = 0; i < n; i++) {
            order.add(sc.next());
        }
        HashMap<String, Integer> freq = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String friend = order.pop();
            freq.put(friend, freq.getOrDefault(friend, 0) + 1);
            if (freq.get(friend) <= 1) {
                out.println(friend);
            }
        }

        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.*;
import java.util.*;
public class da {
    public static void main(String args[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = sc.nextInt();
        Stack<String> order = new Stack<>();
        for (int i = 0; i < n; i++) {
            order.add(sc.next());
        }
        HashMap<String, Integer> freq = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String friend = order.pop();
            freq.put(friend, freq.getOrDefault(friend, 0) + 1);
            if (freq.get(friend) <= 1) {
                System.out.println(friend);
            }
        }

        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.Scanner;

public class Main5 {
public static void main(String[]args) {
	Scanner sc=new Scanner(System.in);
	int a =sc.nextInt();
	String [] x=new String[a];

	for(int i=0;i<a;i++) {
		x[i]=sc.next();
		for(int j=0;j<i;j++) {
			if (x[i].equals( x[j]))
				x[j]=null;

		}
	}

	for(int i=0;i<a;i++) {
		if (x[a-1-i]!=null)
			System.out.println(x[a-1-i]);
	}
}

}


import java.util.HashSet;
import java.util.Scanner;

public class main6 {
	public static void main(String[]args) {
		Scanner sc =new Scanner (System.in);
		int a=sc.nextInt();
		String [] x=new String[a];
		String []y=new String[a];
		HashSet hs=new HashSet<>();
		for(int i=0;i<a;i++) {
			x[i]=sc.next();
		}
		for(int i=0;i<a;i++) {
			if( !hs.contains(x[a-1-i]))
			y[i]=x[a-1-i];
			hs.add(x[a-1-i]);
		}
		for(int i=0;i<a;i++)
			if (y[i]!=null)
				System.out.println(y[i]);
	}

}


import java.util.*;

public class B637 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); in.nextLine();
		Stack<String> st = new Stack<>();
		while(n>0) {
			st.push(in.nextLine());
			n--;
		}
		ArrayList<String> al = new ArrayList<>();
		while(!st.isEmpty()) {
			String temp = st.pop();
			if( !al.contains(temp) ) al.add(temp);
		}
		for( String s : al ) {
			System.out.println(s);
		}
	}
}


import java.util.*;

public class B637 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); in.nextLine();
		Stack<String> st = new Stack<>();
		while(n>0) {
			st.push(in.nextLine());
			n--;
		}
		Set<String> set = new LinkedHashSet<>();
		while(!st.isEmpty()){
			set.add(st.pop());
		}
		Iterator<String> it = set.iterator();
		while(it.hasNext()) {
			System.out.println(it.next());
		}
	}
}


import java.io.*;
import java.util.*;
public class zizo{
	public static void main (String[]args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		Stack<String> st = new Stack<>();
		for(int i = 0 ;i < n ; i++) {
			String a = sc.next();
				st.push(a);
		}
		HashSet<String> hs = new HashSet<>();
		for(int i = 0 ;i < n ; i++) {
			if(!st.isEmpty() && !hs.contains(st.peek()))
				pw.println(st.peek());
			hs.add(st.pop());

		}
		pw.flush();
	}
}


import java.io.*;
import java.util.*;
public class zizo{
	public static void main (String[]args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		Stack<String> st = new Stack<>();
		for(int i = 0 ;i < n ; i++) {
			String a = sc.next();
				st.push(a);
		}
		ArrayList<String> check = new ArrayList<>();
		for(int i = 0 ;i < n ; i++) {
			if(!st.isEmpty() && !check.contains(st.peek()))
				pw.println(st.peek());
			check.add(st.pop());

		}
		pw.flush();
	}
}


import java.io.*;
import java.util.*;
public class zizo{
	public static void main (String[]args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		Stack<String> st = new Stack<>();
		for(int i = 0 ;i < n ; i++)
			st.push(sc.next());
		String x = "";
		for(int i = 0 ;i < n ; i++) {
			if(!st.isEmpty() && !x.contains(st.peek()))
				pw.println(st.peek());
			x = sb.append(st.pop()).toString();
		}
		pw.flush();
	}
}


import java.util.*;
public class chat_order {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        HashSet<String> arr=new HashSet<String>();

        String a[]=new String[n];
        for(int i=0;i<n;i++){
            a[i]=sc.next();
        }
        for(int i=n-1;i>=0;i--){
            if(!arr.contains(a[i])){
                System.out.println(a[i]);
                arr.add(a[i]);
            }
        }

    }
}


import java.util.*;
public class chat_order {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<String> arr=new ArrayList(n);
        String a[]=new String[n];
        for(int i=0;i<n;i++){
            a[i]=sc.next();
        }
        for(int i=n-1;i>=0;i--){
            if(!arr.contains(a[i])){
                System.out.println(a[i]);
                arr.add(a[i]);
            }
        }

    }
}


import java.util.*;
public class chat_order {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<String> arr=new ArrayList(n);
        for(int i=0;i<n;i++){
            String s=sc.next();
            if(arr.contains(s)){
                arr.remove(s);
                arr.add(s);
            }
            else{
                arr.add(s);
            }
        }
        for(int i=arr.size()-1;i>=0;i--){
            System.out.println(arr.get(i));
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Solution implements Runnable {
    private void solve() throws IOException {
        //String str = nextToken();
        int n = nextInt();
       // int m = nextInt();

        Set<String> set = new HashSet<>();
        Deque<String> queue = new LinkedList<>(  );
        for (int i=0; i<n; i++) {
            String name = nextToken();
            queue.addFirst( name );
        }

        for (String name : queue) {
            if (set.add( name ))
                writer.println( name );
        }

    }

    private static void findDP( Node node )
    {
        for ( Node child : node.children )
        {
            if ( child.value > node.value )
            {
                child.dp = Math.max( child.dp, node.dp+1 );
                //findDP( child );
            }
        }
    }

    private static class Obj implements Comparable<Obj> {
        String name;
        int value;

        public Obj(int value) {
            this.value = value;
        }

        public Obj(String name, int value) {
            this.name = name;
            this.value = value;
        }

        @Override
        public int compareTo(Obj o) {
            return o.value-this.value;
        }

    }

    private static class Node
    {
        long value;
        long dp;
        List<Node> children;
        Node parent;

        public Node( int value )
        {
            this.value = value;
            dp = 1;
            children = new ArrayList<Node>();
        }
    }

    private static boolean isInt (String s) {
    	if (s.length() < 1)
    		return false;
    	else {
    		for (char c : s.toCharArray()) {
    			if (c < '0' || c > '9') {
    				return false;
    			}
    		}
    	}

    	return true;
    }

    //mergesort

    public static Comparable[] mergeSort(Comparable[] list)
    {
        if (list.length <= 1) {
            return list;
        }

        Comparable[] left = new Comparable[list.length / 2];
        Comparable[] right = new Comparable[list.length - left.length];
        System.arraycopy(list, 0, left, 0, left.length);
        System.arraycopy(list, left.length, right, 0, right.length);

        mergeSort(left);
        mergeSort(right);

        merge(left, right, list);
        return list;
    }

    private static void merge(Comparable[] left, Comparable[] right, Comparable[] result)
    {
        int leftIdx = 0;
        int rightIdx = 0;
        int index = 0;

        while (leftIdx < left.length && rightIdx < right.length)
        {
            if (left[leftIdx].compareTo(right[rightIdx]) < 0)
            {
                result[index++] = left[leftIdx];
                leftIdx++;
            }
            else
            {
                result[index++] = right[rightIdx];
                rightIdx++;
            }
        }

        System.arraycopy(left, leftIdx, result, index, left.length - leftIdx);
        System.arraycopy(right, rightIdx, result, index, right.length - rightIdx);
    }

    public static List<Obj> mergeSort(List<Obj> list) {
        if (list.size() <= 1) {
            return list;
        }

        List<Obj> left = new ArrayList(list.subList( 0, list.size()/2 ));
        List<Obj> right = new ArrayList (list.subList( left.size(), list.size() ));

        left = mergeSort(left);
        right = mergeSort(right);

        list = merge(left, right);

        return list;
    }

    private static List<Obj> merge(List<Obj> left,List<Obj> right)
   {
      int leftCounter = 0, rightCounter = 0;
       List<Obj> result = new ArrayList<>(  );

       while (leftCounter < left.size() && rightCounter < right.size()) {
           Obj leftItem = left.get( leftCounter );
           Obj rightItem = right.get( rightCounter );

           if ( leftItem.compareTo( rightItem ) < 0) {
               result.add( leftItem );
               leftCounter++;
            }
            else
            {
                result.add( rightItem );
                rightCounter++;
            }
       }

       if (leftCounter >= left.size())
           result.addAll( right.subList( rightCounter, right.size() ) );
       else if (rightCounter >= right.size())
           result.addAll( left.subList( leftCounter, left.size() ) );

       return result;
   }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Solution implements Runnable {
    private void solve() throws IOException {
        //String str = nextToken();
        int n = nextInt();
       // int m = nextInt();

        List<String> list = new ArrayList<>(  );
        for (int i=0; i<n; i++) {
            String name = nextToken();
            if (list.contains( name )) {
                list.remove( name );
                list.add( 0, name );
            }
            else {
                list.add( 0, name );
            }
        }

        for (String name : list)
            writer.println( name );

    }

    private static void findDP( Node node )
    {
        for ( Node child : node.children )
        {
            if ( child.value > node.value )
            {
                child.dp = Math.max( child.dp, node.dp+1 );
                //findDP( child );
            }
        }
    }

    private static class Obj implements Comparable<Obj> {
        String name;
        int value;

        public Obj(int value) {
            this.value = value;
        }

        public Obj(String name, int value) {
            this.name = name;
            this.value = value;
        }

        @Override
        public int compareTo(Obj o) {
            return o.value-this.value;
        }

    }

    private static class Node
    {
        long value;
        long dp;
        List<Node> children;
        Node parent;

        public Node( int value )
        {
            this.value = value;
            dp = 1;
            children = new ArrayList<Node>();
        }
    }

    private static boolean isInt (String s) {
    	if (s.length() < 1)
    		return false;
    	else {
    		for (char c : s.toCharArray()) {
    			if (c < '0' || c > '9') {
    				return false;
    			}
    		}
    	}

    	return true;
    }

    //mergesort

    public static Comparable[] mergeSort(Comparable[] list)
    {
        if (list.length <= 1) {
            return list;
        }

        Comparable[] left = new Comparable[list.length / 2];
        Comparable[] right = new Comparable[list.length - left.length];
        System.arraycopy(list, 0, left, 0, left.length);
        System.arraycopy(list, left.length, right, 0, right.length);

        mergeSort(left);
        mergeSort(right);

        merge(left, right, list);
        return list;
    }

    private static void merge(Comparable[] left, Comparable[] right, Comparable[] result)
    {
        int leftIdx = 0;
        int rightIdx = 0;
        int index = 0;

        while (leftIdx < left.length && rightIdx < right.length)
        {
            if (left[leftIdx].compareTo(right[rightIdx]) < 0)
            {
                result[index++] = left[leftIdx];
                leftIdx++;
            }
            else
            {
                result[index++] = right[rightIdx];
                rightIdx++;
            }
        }

        System.arraycopy(left, leftIdx, result, index, left.length - leftIdx);
        System.arraycopy(right, rightIdx, result, index, right.length - rightIdx);
    }

    public static List<Obj> mergeSort(List<Obj> list) {
        if (list.size() <= 1) {
            return list;
        }

        List<Obj> left = new ArrayList(list.subList( 0, list.size()/2 ));
        List<Obj> right = new ArrayList (list.subList( left.size(), list.size() ));

        left = mergeSort(left);
        right = mergeSort(right);

        list = merge(left, right);

        return list;
    }

    private static List<Obj> merge(List<Obj> left,List<Obj> right)
   {
      int leftCounter = 0, rightCounter = 0;
       List<Obj> result = new ArrayList<>(  );

       while (leftCounter < left.size() && rightCounter < right.size()) {
           Obj leftItem = left.get( leftCounter );
           Obj rightItem = right.get( rightCounter );

           if ( leftItem.compareTo( rightItem ) < 0) {
               result.add( leftItem );
               leftCounter++;
            }
            else
            {
                result.add( rightItem );
                rightCounter++;
            }
       }

       if (leftCounter >= left.size())
           result.addAll( right.subList( rightCounter, right.size() ) );
       else if (rightCounter >= right.size())
           result.addAll( left.subList( leftCounter, left.size() ) );

       return result;
   }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Solution implements Runnable {
    private void solve() throws IOException {
        //String str = nextToken();
        int n = nextInt();
       // int m = nextInt();

        Set<String> set = new HashSet<>();
        Deque<String> queue = new LinkedList<>(  );
        for (int i=0; i<n; i++) {
            String name = nextToken();
            if (set.add( name )) {
                queue.addFirst( name );
            }
            else {
                queue.remove( name );
                queue.addFirst( name );
            }
        }

        for (String name : queue)
            writer.println( name );

    }

    private static void findDP( Node node )
    {
        for ( Node child : node.children )
        {
            if ( child.value > node.value )
            {
                child.dp = Math.max( child.dp, node.dp+1 );
                //findDP( child );
            }
        }
    }

    private static class Obj implements Comparable<Obj> {
        String name;
        int value;

        public Obj(int value) {
            this.value = value;
        }

        public Obj(String name, int value) {
            this.name = name;
            this.value = value;
        }

        @Override
        public int compareTo(Obj o) {
            return o.value-this.value;
        }

    }

    private static class Node
    {
        long value;
        long dp;
        List<Node> children;
        Node parent;

        public Node( int value )
        {
            this.value = value;
            dp = 1;
            children = new ArrayList<Node>();
        }
    }

    private static boolean isInt (String s) {
    	if (s.length() < 1)
    		return false;
    	else {
    		for (char c : s.toCharArray()) {
    			if (c < '0' || c > '9') {
    				return false;
    			}
    		}
    	}

    	return true;
    }

    //mergesort

    public static Comparable[] mergeSort(Comparable[] list)
    {
        if (list.length <= 1) {
            return list;
        }

        Comparable[] left = new Comparable[list.length / 2];
        Comparable[] right = new Comparable[list.length - left.length];
        System.arraycopy(list, 0, left, 0, left.length);
        System.arraycopy(list, left.length, right, 0, right.length);

        mergeSort(left);
        mergeSort(right);

        merge(left, right, list);
        return list;
    }

    private static void merge(Comparable[] left, Comparable[] right, Comparable[] result)
    {
        int leftIdx = 0;
        int rightIdx = 0;
        int index = 0;

        while (leftIdx < left.length && rightIdx < right.length)
        {
            if (left[leftIdx].compareTo(right[rightIdx]) < 0)
            {
                result[index++] = left[leftIdx];
                leftIdx++;
            }
            else
            {
                result[index++] = right[rightIdx];
                rightIdx++;
            }
        }

        System.arraycopy(left, leftIdx, result, index, left.length - leftIdx);
        System.arraycopy(right, rightIdx, result, index, right.length - rightIdx);
    }

    public static List<Obj> mergeSort(List<Obj> list) {
        if (list.size() <= 1) {
            return list;
        }

        List<Obj> left = new ArrayList(list.subList( 0, list.size()/2 ));
        List<Obj> right = new ArrayList (list.subList( left.size(), list.size() ));

        left = mergeSort(left);
        right = mergeSort(right);

        list = merge(left, right);

        return list;
    }

    private static List<Obj> merge(List<Obj> left,List<Obj> right)
   {
      int leftCounter = 0, rightCounter = 0;
       List<Obj> result = new ArrayList<>(  );

       while (leftCounter < left.size() && rightCounter < right.size()) {
           Obj leftItem = left.get( leftCounter );
           Obj rightItem = right.get( rightCounter );

           if ( leftItem.compareTo( rightItem ) < 0) {
               result.add( leftItem );
               leftCounter++;
            }
            else
            {
                result.add( rightItem );
                rightCounter++;
            }
       }

       if (leftCounter >= left.size())
           result.addAll( right.subList( rightCounter, right.size() ) );
       else if (rightCounter >= right.size())
           result.addAll( left.subList( leftCounter, left.size() ) );

       return result;
   }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

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

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

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

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


import org.omg.CORBA.portable.InputStream;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Андрей on 13.03.2016.
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        List<String> lst = new ArrayList<>();
        long a=System.currentTimeMillis();
/*
        try (BufferedReader reader =new BufferedReader(new InputStreamReader(System.in))) {
            int count = Integer.valueOf(reader.readLine());
            String line;
            for(int i = 0; i < count; i++) {
                lst.add(reader.readLine());
            }
        }*/

      try (Scanner reader =new Scanner(System.in)) {
            int count = reader.nextInt();
            String line;
            for(int i = 0; i < count; i++) {
               lst.add(reader.nextLine());
            }
        }
        //System.out.println(System.currentTimeMillis()-a);
        long b=System.currentTimeMillis();
        List<String> end_list = new ArrayList<>();
        for (int i=lst.size()-1;i>=0;i--){
            if(!end_list.contains(lst.get(i)))end_list.add(lst.get(i));
        }
        end_list.forEach(System.out::println);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Андрей on 13.03.2016.
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        List<String> lst = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int count = Integer.valueOf(reader.readLine());
            for (int i = 0; i < count; i++) {
                lst.add(reader.readLine());
            }
        }
        List<String> end_list = new ArrayList<>();
        for (int i=lst.size()-1;i>=0;i--){
            if(!end_list.contains(lst.get(i)))end_list.add(lst.get(i));
        }
        end_list.forEach(System.out::println);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Андрей on 13.03.2016.
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        List<String> lst = new ArrayList<>();
        long a=System.currentTimeMillis();
        try (BufferedReader reader =new BufferedReader(new InputStreamReader(System.in))) {
            int count = Integer.valueOf(reader.readLine());
            String line;
            for(int i = 0; i < count; i++) {
               line=reader.readLine();
               lst.add(line);
            }
        }
        System.out.println(System.currentTimeMillis()-a);
        long b=System.currentTimeMillis();
        List<String> end_list = new ArrayList<>();
        for (int i=lst.size()-1;i>=0;i--){
            if(!end_list.contains(lst.get(i)))end_list.add(lst.get(i));
        }
        end_list.forEach(System.out::println);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Андрей on 13.03.2016.
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        List<String> lst = new ArrayList<>();
        long a=System.currentTimeMillis();
        try (BufferedReader reader =new BufferedReader(new InputStreamReader(System.in))) {
            int count = Integer.valueOf(reader.readLine());
            String line;
            for(int i = 0; i < count; i++) {
               line=reader.readLine();
               lst.add(line);
            }
        }
        long b=System.currentTimeMillis();
        List<String> end_list = new ArrayList<>();
        for (int i=lst.size()-1;i>=0;i--){
            if(!end_list.contains(lst.get(i)))end_list.add(lst.get(i));
        }
        end_list.forEach(System.out::println);
    }
}


import org.omg.CORBA.portable.InputStream;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Андрей on 13.03.2016.
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        List<String> lst = new ArrayList<>();
/*
        try (BufferedReader reader =new BufferedReader(new InputStreamReader(System.in))) {
            int count = Integer.valueOf(reader.readLine());
            String line;
            for(int i = 0; i < count; i++) {
                lst.add(reader.readLine());
            }
        }*/

      try (Scanner reader =new Scanner(System.in)) {
            int count =Integer.valueOf(reader.nextLine());
            for(int i = 0; i < count; i++) {
               lst.add(reader.nextLine());
            }
        }

        long b=System.currentTimeMillis();
        List<String> end_list = new ArrayList<>();
        for (int i=lst.size()-1;i>=0;i--){
            if(!end_list.contains(lst.get(i)))end_list.add(lst.get(i));
        }
        end_list.forEach(System.out::println);
    }
}


import org.omg.CORBA.portable.InputStream;

import java.io.*;
import java.util.*;

/**
 * Created by Андрей on 13.03.2016.
 */
public class Main2 {
    public static void main(String[] args) throws IOException {
        List<String> lst = new ArrayList<>();
        try (BufferedReader reader =new BufferedReader(new InputStreamReader(System.in))) {
            int count = Integer.valueOf(reader.readLine());
            String line;
            for(int i = 0; i < count; i++) {
                lst.add(reader.readLine());
            }
        }

 /*     try (Scanner reader =new Scanner(System.in)) {
            int count =Integer.valueOf(reader.nextLine());
            for(int i = 0; i < count; i++) {
               lst.add(reader.nextLine());
            }
        }*/

        Set<String> end_list = new LinkedHashSet<>();
        for (int i=lst.size()-1;i>=0;i--){
            if(!end_list.contains(lst.get(i)))end_list.add(lst.get(i));
        }
        end_list.forEach(System.out::println);

    }
}


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

public class o2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] ns = new String[n];
        for (int a = 0; a < n; a++) {
            ns[a] = reader.readLine();
        }

        ArrayList<String> dialogs = new ArrayList<>();
        for (int a = 0; a < n; a++) {
            if (dialogs.isEmpty()) {
                dialogs.add(0, ns[a]);
            } else {
                for (int b = 0; b < dialogs.size(); b++) {
                    if (ns[a].equals(dialogs.get(b)))
                        dialogs.remove(b);
                }
                dialogs.add(0, ns[a]);
            }
        }
        for (int a = 0; a < dialogs.size(); a++) {
            System.out.println(dialogs.get(a));
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;

public class o3 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        Stack<String> s = new Stack<>();
        for (int a = 0; a < n; a ++) {
            s.push(reader.readLine());
        }
        Set<String> set = new HashSet<>();
        for (;!s.isEmpty();) {
            String peop = s.pop();
            if (!set.contains(peop)) {
                set.add(peop);
                System.out.println(peop);
            }
        }
    }
}


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

public class o2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] ns = new String[n];
        for (int a = 0; a < n; a++) {
            ns[a] = reader.readLine();
        }

        ArrayList<String> dialogs = new ArrayList<>();
        for (int a = 0; a < n; a++) {
                dialogs.remove(ns[a]);
                dialogs.add(0, ns[a]);
        }
        for (int a = 0; a < dialogs.size(); a++) {
            System.out.println(dialogs.get(a));
        }
    }
}


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

public class o2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        ArrayList<String> dialogs = new ArrayList<>();
        for (int a = 0; a < n; a++) {
            String lol = reader.readLine();
            dialogs.remove(lol);
            dialogs.add(0, lol);
        }
        for (int a = 0; a < dialogs.size(); a++) {
            System.out.println(dialogs.get(a));
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class o2 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] ns = new String[n];
        for (int a = 0; a < n; a++) {
            ns[a] = reader.readLine();
        }

        LinkedList<String> dialogs = new LinkedList<>();
        for (int a = 0; a < n; a++) {
                dialogs.remove(ns[a]);
                dialogs.add(0, ns[a]);
        }
        for (int a = 0; a < dialogs.size(); a++) {
            System.out.println(dialogs.get(a));
        }
    }
}