#include<iostream>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int **array=new int *[row] ;
    for(int i=0;i<row;i++)
        array[i]=new int [col] ;
        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        int *t=new int [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if(t[1]<=row)
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if(t[1]<=col){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
            }
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int array[row][col] ;
    memset(array,0,sizeof(array)) ;

        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        double *t=new double [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if((t[1]<=row) and(t[1]>=1))
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    if((t[2]<=1000000000) and(t[2]>=1)){
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                    }
                    else
                        return 0 ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if((t[1]<=col) and(t[1]>=1)){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                if((t[2]<=1000000000) and(t[2]>=1)){
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
                }
                else
                    return 0 ;
            }
                else
                    return 0 ;
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
}


#include<iostream>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int **array=new int *[row] ;
    for(int i=0;i<row;i++)
        array[i]=new int [col] ;
        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        double *t=new double [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if((t[1]<=row) and(t[1]>=1))
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    if((t[2]<=1000000000) and(t[2]>=1)){
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                    }
                    else
                        return 0 ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if((t[1]<=col) and(t[1]>=1)){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                if((t[2]<=1000000000) and(t[2]>=1)){
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
                }
                else
                    return 0 ;
            }
                else
                    return 0 ;
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
}


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

int main()
{
    int row,col,cases ;
    cin>>row>>col>>cases ;
    int one[5001] ,two[5001];
    memset(one,0,sizeof one) ;
    memset(two,0,sizeof two) ;
    int x ,y ,new_array[100001] ;
    memset(new_array,0,sizeof new_array) ;
    for(int i=1;i<=cases;++i)
    {
        cin>>x>>y>>new_array[i] ;
        if(x==1)
        {
            one[y-1]=i ;
        }
        else if(x==2)

            two[y-1]=i ;
    }
    for(int i=0;i<row;++i)
    {
        for(int j=0;j<col;++j)
        {
            cout<<new_array[max(one[i],two[j])]<<" " ;
        }
        cout<<endl ;
        }
    }


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    int x=0;
    int n;
    cin>>n;
 if((n>=1)and(n<=150))
 {
     for(int i=0;i<n;i++)
        {
            cin>>s;
            if((s=="x++")or(s=="++x"))
                x=x+1;
             else if((s=="x--")or(s=="--x"))
                x=x-1;
                else
                    return 0 ;

 }
 cout<<x<<endl;
}
else
    return 0 ;
}


#include<iostream>
using namespace std ;
int main()
{
    int row ,col ,cases ;
    cin>>row ;
    if((row>=1) and(row<=5000))
    {
    cin>>col ;
    if((col>=1) and(col<=5000) and(row*col<=100000))
    {
    int **array=new int *[row] ;
    for(int i=0;i<row;i++)
        array[i]=new int [col] ;
        for(int i=0;i<row;i++)
        for(int j=0;j<col;j++)
        a[i][j]=0 ;
        cin>>cases ;
        if((cases>=1) and(cases<=100000))
        {
        double *t=new double [3] ;
        for(int i=0;i<cases;i++)
        {
            cin>>t[0] ;
            if(t[0]==1)
            {
                cin>>t[1] ;
                if((t[1]<=row) and(t[1]>=1))
                {
                    int dif=t[1]-1 ;
                    cin>>t[2] ;
                    if((t[2]<=1000000000) and(t[2]>=1)){
                    for(int z=0;z<col;z++)
                      array[dif][z]=t[2] ;
                    }
                    else
                        return 0 ;
                }
            }
            else if(t[0]==2)
            {
                cin>>t[1] ;
                if((t[1]<=col) and(t[1]>=1)){
                int dif=t[1]-1 ;
                cin>>t[2] ;
                if((t[2]<=1000000000) and(t[2]>=1)){
                for(int z=0;z<row;z++)
                    array[z][dif]=t[2] ;
                }
                else
                    return 0 ;
            }
                else
                    return 0 ;
            }
            else
                return 0 ;
        }
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++)
                cout<<array[i][j]<<" " ;
            cout<<endl ;
        }
        }
        else
            return 0 ;
    }
    else
        return 0 ;
}
    else
        return 0 ;
}


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

int main()
{
    int row,col,cases ;
    cin>>row>>col>>cases ;
    int one[cases] ,two[cases];
    memset(one,0,sizeof one) ;
    memset(two,0,sizeof two) ;
    int x ,y ,new_array[row*col] ;
    memset(new_array,0,sizeof new_array) ;
    for(int i=1;i<=cases;++i)
    {
        cin>>x>>y>>new_array[i] ;
        if(x==1)
        {
            one[y-1]=i ;
        }
        else
            two[y-1]=i ;
    }
    for(int i=0;i<row;++i)
    {
        for(int j=0;j<col;++j)
        {
            cout<<new_array[max(one[i],two[j])]<<" " ;
        }
        cout<<endl ;
        }
    }


#include <iostream>
using namespace std;
int a[5005][5005];
int n,m;
void fja(int op,int x,int b)
{
    if(op==1)
    {
        for(int i=1;i<=m;i++)
        {
            a[x][i] = b;
        }
    }
    if(op==2)
    {
        for(int i=1;i<=n;i++)
        {
            a[i][x] =b;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    int k,p,x,y;
    cin>>n>>m>>k;
    for(int i=0;i<k;i++)
    {
        cin>>p>>x>>y;
        fja(p,x,y);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int a[5005][5005];
int n,m;
void fja(int op,int x,int b)
{
    if(op==1)
    {
        for(int i=1;i<=m;i++)
        {
            a[x][i] = b;
        }
    }
    if(op==2)
    {
        for(int i=1;i<=n;i++)
        {
            a[i][x] =b;
        }
    }
}
int main()
{
    int k,p,x,y;
    cin>>n>>m>>k;
    for(int i=0;i<k;i++)
    {
        cin>>p>>x>>y;
        fja(p,x,y);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

const int maxn = 10005;
int n, m;
int a[maxn][2], b[maxn][2];

int main()
{
	int z;
	cin>>n>>m>>z;
	for (int i = 1; i <= z; i++)
	{
		int x,t,c;
		cin>>t>>x>>c;
		x--;
		if (t == 1)
		{
			a[x][0] = c;
			a[x][1] = i;
		}
		else
		{
			b[x][0] = c;
			b[x][1] = i;
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][1] > b[j][1])
				cout<<a[i][0]<<" ";
			else
				cout<<b[j][0]<<" ";
		}
		cout<<endl;
	}

	return 0;
}


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

const int maxn = 10005;
int n, m;
int a[maxn][2], b[maxn][2];

int main()
{
	int z;
	cin>>n>>m>>z;
	for (int i = 1; i <= z; i++)
	{
		int x,t,c;
		cin>>t>>x>>c;
		x--;
		if (t == 1)
		{
			a[x][0] = c;
			a[x][1] = i;
		}
		else
		{
			b[x][0] = c;
			b[x][1] = i;
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][1] > b[j][1])
				cout<<a[i][0]<<" ";
			else
				cout<<a[j][0]<<" ";
		}
		cout<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int low[5005];
int high[5005];
int arr[5005][5005];
vector < pair<int,pair<int,int> > > q;
int main()
{
	ios::sync_with_stdio(false);
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		q.push_back(make_pair(a,make_pair(b-1,c)));
	}
	for(int i = 0 ; i<q.size();i++)
	{
		if(q[i].first == 1)
		{
			int y=q[i].second.first;
			for(int j=0;j<m;j++)
				arr[y][j]=q[i].second.second;
		}
		else
		{
			int y=q[i].second.first;
			for(int j=0;j<n;j++)
				arr[j][y]=q[i].second.second;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
			cout<<arr[i][j]<<" ";
		cout<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int low[100005];
int high[100005];
int arr[5005][5005];
int main()
{
	ios::sync_with_stdio(false);
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<k;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(a==1)low[b-1]=c;
		else high[b-1]=c;
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			arr[i][j]=low[i];
	for(int i=0;i<m;i++)
		for(int j=0;j<n;j++)
			arr[j][i]=high[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cout<<arr[i][j]<<" ";
		cout<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int arr[5005][5005];
vector < pair<int,pair<int,int> > > q;
map< pair<int,int>,int >Map;
int main()
{
	ios::sync_with_stdio(false);
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		pair<int,int>t = make_pair(a,b-1);
		if(Map.count(t))
		{
			q[Map[t]].second.second = c;
		}
		else{
			Map[t] = i;
			q.push_back(make_pair(a,make_pair(b-1,c)));
		}
	}
	for(int i = 0 ; i<int(q.size());i++)
		{
			if(q[i].first == 1)
			{
				int y=q[i].second.first;
				for(int j=0;j<m;j++)
					arr[y][j]=q[i].second.second;
			}
			else
			{
				int y=q[i].second.first;
				for(int j=0;j<n;j++)
					arr[j][y]=q[i].second.second;
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
				printf("%d ",arr[i][j]);
			printf("\n");
		}
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int arr[5005][5005];
vector < pair<int,pair<int,int> > > q;
int main()
{
	ios::sync_with_stdio(false);
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		q.push_back(make_pair(a,make_pair(b-1,c)));
	}
	for(int i = 0 ; i<q.size();i++)
	{
		if(q[i].first == 1)
		{
			int y=q[i].second.first;
			for(int j=0;j<m;j++)
				arr[y][j]=q[i].second.second;
		}
		else
		{
			int y=q[i].second.first;
			for(int j=0;j<n;j++)
				arr[j][y]=q[i].second.second;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
			printf("%d ",arr[i][j]);
		printf("\n");
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int,int>lo[100010],f[100010];
int main()
{
	int n,m,k; cin>>n>>m>>k;
	for(int i = 1 ; i <=k;i++)
	{
		int a,b,c; cin>>a>>b>>c;
		if(a==1)
			f[b] = make_pair(i,c);
		else
			lo[b] = make_pair(i,c);
	}

	for(int i = 1;i<=n;i++)
	{
		for(int j = 1;j<=m;j++)
		{
			if(f[i].first > lo[j].first)
				cout<<f[i].second<<" ";
			else
				cout<<lo[j].second<<" ";
		}
		cout<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int arr[5005][5005];
pair<int,int> lastr[5005];
pair<int,int> lastc[5005];
int main()
{
	ios::sync_with_stdio(false);
	memset(lastr,(-1,0),sizeof(lastr));
	memset(lastc,(-1,0),sizeof(lastc));
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<k;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
        if(a==1)
            lastr[b-1]=make_pair(i,c);
        else
            lastc[b-1]=make_pair(i,c);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(lastr[i].first>=lastc[j].first)cout<<lastr[i].second<<" ";
            else cout<<lastc[j].second<<" ";
        }
        cout<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int,int>lo[100010],f[100010];
int main()
{
	int n,m,k; cin>>n>>m>>k;
	for(int i = 1 ; i <=k;i++)
	{
		int a,b,c; cin>>a>>b>>c;
		if(a==1)
			f[b] = make_pair(i,c);
		else
			lo[b] = make_pair(i,c);
	}

	for(int i = 1;i<=n;i++)
	{
		int fq = 1;
		for(int j = 1;j<=m;j++)
		{
			if(fq == 1) fq++;
			else cout<<" ";
			if(f[i].first > lo[j].first)
				cout<<f[i].second;
			else
				cout<<lo[j].second;
		}
		cout<<endl;
	}
}


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

int main(){
	int n,m,k; cin>>n>>m>>k;

	map <int, int> m1, m2;
	int row[5002], column[5002];
	memset(row,0,sizeof row);
	memset(column,0,sizeof column);
	for(int i = 0; i < k; i++){
		int x,y,z; cin>>x>>y>>z;

		if(x == 1){
			row[y] = z;
			m1[y] = z;
		}else if(x == 2){
			column[y] = z;
			m2[y] = z;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(j != m){
				if(!m1.count(i) && !m2.count(j)) cout<<"0 ";
				else{
					cout<<max(m1[i] , m2[j])<<" ";
				}
			}else{
					if(!m1.count(i) && !m2.count(j)) cout<<0;
					else{
						cout<<max(m1[i] , m2[j]);
					}
			}
		}
		cout<<endl;
	}
}


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

int main(){
	int n,m,k; cin>>n>>m>>k;

	map <int, int> m1, m2;
	int row[5002], column[5002];
	memset(row,0,sizeof row);
	memset(column,0,sizeof column);
	for(int i = 1; i <= k; i++){
		int x,y,z; cin>>x>>y>>z;

		if(x == 1){
			row[y] = z;
			m1[y] = k;
		}else if(x == 2){
			column[y] = z;
			m2[y] = k;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(!m1.count(i) && !m2.count(j)) cout<<"0 ";
			else{
				if(m1[i] >= m2[j]) cout<<row[i]<<" ";
				else cout<<column[j]<<" ";
			}

		}
		cout<<endl;
	}
}


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

#define pb push_back

int main(){
	int n,m,k; cin>>n>>m>>k;
	int arr[n][m];
	memset(arr,0,sizeof arr);
	for(int i = 0; i < k; i++){
		int x,y,z;
		cin>>x>>y>>z;
		if(x == 1){
			for(int j = 0;j < m; j++){
				arr[y-1][j] = z;
			}
		}else if(x == 2){
			for(int j = 0;j < n; j++){
				arr[j][y-1] = z;
			}
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(j != m - 1) cout<<arr[i][j]<<" ";
			else{
				cout<<arr[i][j];
			}
		}
		cout<<endl;
	}

}


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

int main(){
	int n,m,k; cin>>n>>m>>k;

	map <int, int> m1, m2;
	int row[5002], column[5002];
	memset(row,0,sizeof row);
	memset(column,0,sizeof column);
	for(int i = 0; i < k; i++){
		int x,y,z; cin>>x>>y>>z;

		if(x == 1){
			row[y] = z;
			m1[y] = z;
		}else if(x == 2){
			column[y] = z;
			m2[y] = z;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(j != m){
				if(!m1.count(i) && !m2.count(j)) cout<<"0 ";
				else{
					cout<<max(m1[i] , m2[j])<<" ";
				}
			}else{
					if(!m1.count(i) && !m2.count(j)) cout<<0;
					else{
						cout<<max(m1[i] , m2[j]);
					}
			}
		}
		cout<<endl;
	}
	cout<<endl;
}


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

int main(){
	int n,m,k; cin>>n>>m>>k;

	map <int, int> m1, m2;
	int row[5002], column[5002];
	memset(row,0,sizeof row);
	memset(column,0,sizeof column);
	for(int i = 1; i <= k; i++){
		int x,y,z; cin>>x>>y>>z;

		if(x == 1){
			row[y] = z;
			m1[y] = i;
		}else if(x == 2){
			column[y] = z;
			m2[y] = i;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(!m1.count(i) && !m2.count(j)) cout<<"0 ";
			else if(m1.count(i) && m2.count(j) ){
				if(m1[i] >  m2[j]) cout<<row[i]<<" ";
				else cout<<column[j]<<" ";

			}else if(m1.count(i)) cout<<row[i]<<" ";
			else cout<<column[j]<<" ";

		}
		cout<<endl;
	}
}


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

int main(){
	int n,m,k; cin>>n>>m>>k;

	map <int, int> m1, m2;
	int row[5002], column[5002];

	for(int i = 0; i < k; i++){
		int x,y,z; cin>>x>>y>>z;

		if(x == 1){
			row[y] = z;
			m1[y] = z;
		}else if(x == 2){
			column[y] = z;
			m2[y] = z;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(j != m){
				if(!m1.count(i) && !m2.count(j)) cout<<0 + " ";
				else{
					cout<<max(m1[i] , m2[j]) + " ";
				}
			}else{
					if(!m1.count(i) && !m2.count(j)) cout<<0;
					else{
						cout<<max(m1[i] , m2[j]);
					}
			}
		}
		cout<<endl;
	}
}


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

#define pb push_back

int main(){
	int n,m,k; cin>>n>>m>>k;
	int arr[n][m] = {0};
	for(int i = 0; i < k; i++){
		int x,y,z;
		cin>>x>>y>>z;
		if(x == 1){
			for(int j = 0;j < m; j++){
				arr[y-1][j] = z;
			}
		}else if(x == 2){
			for(int j = 0;j < n; j++){
				arr[j][y-1] = z;
			}
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(j != m - 1) cout<<arr[i][j]<<" ";
			else{
				cout<<arr[i][j];
			}
		}
		cout<<endl;
	}

}


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

int main(){
	int n,m,k; cin>>n>>m>>k;

	map <int, int> m1, m2;
	int row[5002], column[5002];

	for(int i = 0; i < k; i++){
		int x,y,z; cin>>x>>y>>z;

		if(x == 1){
			row[y] = z;
			m1[y] = z;
		}else if(x == 2){
			column[y] = z;
			m2[y] = z;
		}
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(j != m){
				if(!m1.count(i) && !m2.count(j)) cout<<0 + " ";
				else{
					cout<<max(m1[i] , m2[j]) + " ";
				}
			}else{
					if(!m1.count(i) && !m2.count(j)) cout<<0;
					else{
						cout<<max(m1[i] , m2[j]);
					}
			}
		}
		cout<<endl;
	}
	cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define MAX 5050

int n, m, k;
int g[MAX][MAX];
vector < string > s;

int main ( )
{
    ios_base :: sync_with_stdio ( 0 );
//    freopen ( "input.txt", "r", stdin );

    scanf ( "%d %d %d", &n, &m, &k );

    memset ( g, 0, sizeof ( g ) );

    while ( k -- )
    {
        int q, c, a;

        scanf ( "%d %d %d", &q, &c, &a );

        if ( q == 1 )
        {
            for ( int i = 1; i <= m; ++ i )
            {
                g[c][i] = a;
            }
        }
        else
        {
            for ( int i = 1; i <= n; ++ i )
            {
                g[i][c] = a;
            }
        }
    }

    s.resize ( MAX );

    for ( int i = 1; i <= n; ++ i )
    {
        for ( int j = 1; j <= m; ++ j )
        {
            if ( g[i][j] == 0 )
            {
                s[i].pb ( '0' );
            }
            else
            while ( g[i][j] > 0 )
            {
                s[i].pb ( g[i][j] % 10 + '0' );
                g[i][j] /= 10;
            }
            if ( j != m ) s[i].pb ( ' ' );
        }
        s[i].pb ( '\n' );
    }

    for ( int i = 1; i <= n; ++ i )
    {
        printf ( "%s", s[i].c_str ( ) );
    }

    return 0;
}


using namespace std;
bool debug = false;

//<editor-fold desc="GUAXINIM TEMPLATE">
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define space " "

typedef pair<int,int> pii;
typedef vector<int> vi;

/// Debug Start
template<class T1> void deb(T1 e1)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << endl;
    }
}
template<class T1,class T2> void deb(T1 e1, T2 e2)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << endl;
    }
}
template<class T1,class T2,class T3> void deb(T1 e1, T2 e2, T3 e3)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << endl;
    }
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1, T2 e2, T3 e3, T4 e4)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1, T2 e2, T3 e3, T4 e4 ,T5 e5, T6 e6)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << space << e6 << endl;
    }
}

template<typename T>
void print_vector_debug(const T& t) {

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            if ((i + 1) != t.cend()) {
                cout << *i << " ";
            } else {
                cout << *i << endl;
            }
        }
    }
}

template<typename T>
void print_array_debug(const T arr, int size){

    if(debug) {
        cout << "[DEBUG] VECTOR:";
        for (int i = 0; i < size; ++i) {
            cout << arr[i] << space;
        }
        cout << endl;
    }
}

template<typename T>
void print_2Darray_debug(const T arr, int rows, int cols){

    if(debug) {
        cout << "[DEBUG] Matrix:" << endl;
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                cout << arr[i][j] << space;
            }
            cout << endl;
        }
        cout << endl;
    }
}

template<typename T>
void print_matrix_debug(const T& t) {
    if(debug) {
        cout << "[DEBUG] MATRIX:" << endl;
        for (auto i = t.cbegin(); i != t.cend(); ++i) {
            for(auto j = i->cbegin(); j != i->cend(); ++j){
                cout << *j << " ";
            }
            cout << endl;
        }
    }
}
//</editor-fold>

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

    int N;
    cin >> N;

    vi freq(5000000,0);

    vi need_change;
    int val;
    for (size_t i = 0; i < N; i++) {
        cin >> val;
        if(freq[val] == 1){
            need_change.push_back(val);
        }
        freq[val] = 1;
    }

    sort(all(need_change));
    print_vector_debug(need_change);

    int acu = 0;
    int notUsed = 0;
    for(auto &e : need_change){

        while(freq[notUsed] == 1 || notUsed <= e){
            ++notUsed;
        }

        acu += notUsed - e;
        freq[notUsed] = 1;

    }

    cout << acu << endl;

    return 0;
}

// 1522437583302


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

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int count[3100] = {0};
	for(int i = 0;i<n;i++){
		cin >> count[i];
	}
	sort(count,count+n);
	ll res = 0;
	for(int i = 1;i<n;i++){
		if(count[i] == count[i-1]){
			res++;
			count[i]++;
		}
		if(count[i] < count[i-1]){
			int aux = count[i];
			count[i] += count[i-1]-aux+1;
			res += count[i-1]-aux+1;
		}
	}
	cout << res << '\n';

	return 0;
}

// 1522432971659


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

int main(){
	int n,x, answ=0,k;
	std::vector<int> rcvd;
	rcvd.clear();
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		rcvd.push_back(x);
	}
	sort(rcvd.begin(), rcvd.end());
	k = rcvd[0]; //menor que ha
	for (int i = k; i < (n+k); ++i)
	{
		if (rcvd[i-k] < i)
		{
			answ+= abs(rcvd[i-k] - i);
		}

	}

	cout << answ << endl;

return 0;
}
// 1497033584606


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

vector<int> badge;
priority_queue<int> zero;
priority_queue<int> rep;
int main(){

	int i,j,k,aux,flag;
	long long int n, sum;

	cin >> n;
	badge.assign(n+1, 0);

	for(i=0;i<n;i++) {
		cin >> aux;
		badge[aux]++;
	}

	for(i=1;i<=n;i++){
		if(badge[i]==0) zero.push(i*(-1));
		else if(badge[i]>1){
			for(j=1;j<badge[i];j++) rep.push((-1)*i);
		}
	}

	flag=0;
	sum=0;
	while(!flag&&(!zero.empty() || !rep.empty())){
		i=(-1)*zero.top();
		j=(-1)*rep.top();
		if(i>j) {
			sum += i-j;
			zero.pop();
			rep.pop();
		} else {
			flag=1;
		}
	}

/*	while(!zero.empty()){
		sum+=(-1)*zero.top();
		zero.pop();
	}*/

	aux=n+1;
	while(!rep.empty()){
		sum+=aux-(-1)*rep.top();
		rep.pop();
		aux++;
	}

	cout << sum << endl;

	return 0;
}

// 1497032891227


#include <cassert>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
#include <functional>
//#include <unordered_map>
#include <climits>

using namespace std;

typedef int s32;
typedef long long s64;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

void solve(int n, int *arr) {
    int correct = ((1 + n) * n) / 2;
    s64 sum = 0;
    for (int i = 0; i < n; i++) {
        sum += arr[i];
    }

    s64 r = (correct - sum);
    r = r > 0 ? r : -r;

    printf("%lld\n", r);
}

int main(int argc, char** argv) {
    //int tests;
    //scanf(" %d", &tests);
    //for (int i = 0; i < tests; i++) {
        int n;
        scanf(" %d", &n);
        int vec[9000] = {0};
        for (int j = 0; j < n; j++) {
            scanf(" %d", &vec[j]);
        }

        solve(n, vec);
    //}

    // tests

    return 0;
}

// 1522437841429


#include<bits/stdc++.h>
using namespace std;
int main(){
    int i, n, j, aux;
    aux=0;
    scanf("%i", &n);
    int med[n];
    for(i=0; i<n; i++){
        scanf("%i", &med[i]);
    }
    sort(med, med+n);
    for(j=0; j<n; j++){
        for(i=0; i<n; i++){
            if(med[i]==med[i+1]){
            med[i+1]++;
            aux++;
            }
        }
    }
    printf("%i", aux);
    return(0);
}

// 1481138315771


using namespace std;
bool debug = false;

//<editor-fold desc="GUAXINIM TEMPLATE">
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define space " "

typedef pair<int,int> pii;
typedef vector<int> vi;

/// Debug Start
template<class T1> void deb(T1 e1)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << endl;
    }
}
template<class T1,class T2> void deb(T1 e1, T2 e2)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << endl;
    }
}
template<class T1,class T2,class T3> void deb(T1 e1, T2 e2, T3 e3)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << endl;
    }
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1, T2 e2, T3 e3, T4 e4)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << endl;
    }
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1, T2 e2, T3 e3, T4 e4 ,T5 e5, T6 e6)
{
    if(debug) {
        cout << "[DEBUG]";
        cout << e1 << space << e2 << space << e3 << space << e4 << space << e5 << space << e6 << endl;
    }
}
//</editor-fold>

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

    int N;
    cin >> N;

    vi freq(1000000,0);

    vi need_change;
    int val;
    for (int i = 0; i < N; i++) {
        cin >> val;
        if(freq[val] == 1){
            need_change.push_back(val);
        }
        freq[val] = 1;
    }

    sort(all(need_change));

    int acu = 0;
    int notUsed = 0;
    for(int &e : need_change){

        while(freq[notUsed] == 1 || notUsed <= e){
            ++notUsed;
        }

        acu += notUsed - e;
        freq[notUsed] = 1;

    }

    cout << acu << endl;

    return 0;
}

// 1522437990254


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,cont=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=1;i<n;i++){
		if(a[i]<=a[i-1]){
			cont+=a[i-1]-a[i]+1;
			a[i]+= a[i-1]-a[i]+1;
		}
	}
	cout<<cont<<endl;
	return 0;
}
// 1516020930601


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

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int count[3100] = {0};
	for(int i = 0;i<n;i++){
		int k;
		cin >> k;
		count[k]++;
	}
	bool s = true;
	ll res = 0;
	while(s){
		s = false;
		for(int i = 0;i<=n;i++){
			if(count[i] > 1){
				s = true;
				res += count[i]-1;
				count[i+1] += count[i]-1;
				count[i] = 1;
			}
		}
	}
	cout << res << '\n';

	return 0;
}

// 1522432658760


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

vector<int> badge;
vector<int> repetido;
int main(){

	int i,j,k,aux,flag;
	long long int n, sum;

	cin >> n;
	badge.assign(100100, 0);

	sum=0;
	for(i=0;i<n;i++) {
		cin >> aux;
		while(badge[aux]!=0) {
			sum++;
			aux++;
		}
		badge[aux]++;
	}

	cout << sum << endl;

	return 0;
}

// 1497039621758


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

    int main(){

     int n,k=0;

        scanf("%d",&n);

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

        sort(soldados,soldados+n);

        for(int i=1;i<n;i++){
                if(soldados[i]==soldados[i-1]){
                    soldados[i]++;
                    k++;
                }
            }
            printf("%d\n",k);
    }

// 1512584163301


#include <iostream>
using namespace std;
int n,b,b1;
int money = 0;
int badge[3000];

int force()
{
	for(b1 = 0; b1 < n; b1++)
	{
		if(b1 == b)
		{
			b1++;
		}
		if(badge[b] == badge[b1])
		{
			badge[b] = badge[b] + 1;
			money = money +1;
			force();
		}
	}
}

int main()
{
	cin >> n;

	for(int a = 0; a < n; a++)
	{
		cin >> badge[a];
	}

	for(b =0; b < n; b++)
	{
		force();
	}
	cout << money;
}


#include <iostream>
using namespace std;
int n,b,b1;
int sky =0;
int money = 0;

int main()
{
	cin >> n;
	int badge[n-1];
	for(int a = 0; a < n; a++)
	{
		cin >> badge[a];
	}

	for(b =0; b < n;)
	{
		sky = 0;
		for(b1 = b+1; b1 < n; b1++)
		{
			if(badge[b] == badge[b1])
			{
				badge[b] = badge[b] + 1;
				money = money +1;
				sky = 1;
			}
		}
		if(sky == 0)
		{
			b++;
		}
	}
	cout << money;
}


#include <iostream>
using namespace std;

int main()
{
	int x[1000];
	int amt;
	int swap;
	int coins = 0;
	cin >> amt;
	for(int a =0; a < amt; a++)
	{
		cin >> x[a];
	}
	for(int h = 0; h < amt-1; h++)
	{
		for(int i = 0; i < amt-1; i++)
		{
			if(x[i] < x[i+1])
			{
				swap = x[i];
				x[i] = x[i+1];
				x[i+1] = swap;
			}
		}
	}
	for(int j = 0; j < amt -1; j++)
	{
		for(int k = 0; k < amt-1; k++)
		{
			if(x[k] == x[k+1])
			{
				x[k+1] = x[k+1]+1;
				coins = coins +1;
			}
		}
	}
	cout << coins;
}


#include <iostream>
using namespace std;

int main()
{
	int x[1000];
	int amt;
	int swap;
	int coins = 0;
	int chill = 0;
	cin >> amt;
	for(int a =0; a < amt; a++)
	{
		cin >> x[a];
	}
	for(int h = 0; h < amt-1; h++)
	{
		for(int i = 0; i < amt-1; i++)
		{
			if(x[i] < x[i+1])
			{
				swap = x[i];
				x[i] = x[i+1];
				x[i+1] = swap;
			}
		}
	}
	for(int j = 0; j > -1; j++)
	{
		chill = 0;
		for(int k = 0; k < amt-1; k++)
		{
			if(x[k] == x[k+1])
			{
				x[k] = x[k]+1;
				coins = coins +1;
			}
			if(x[k] != x[k+1])
			{
				chill = chill +1;
			}
		}
		if(chill == amt)
		{
			break;
		}

	}
	cout << coins;
}


#include <iostream>
using namespace std;

int main()
{
	int x[10000];
	int amt;
	int swap;
	int coins = 0;
	int chill = 0;
	cin >> amt;
	for(int a =0; a < amt; a++)
	{
		cin >> x[a];
	}
	for(int h = 0; h < amt-1; h++)
	{
		for(int i = 0; i < amt-1; i++)
		{
			if(x[i] < x[i+1])
			{
				swap = x[i];
				x[i] = x[i+1];
				x[i+1] = swap;
			}
		}
	}
	for(int j = 0; j < amt -1; j++)
	{

		for(int k = 0; k < amt-1; k++)
		{
			if(x[k] == x[k+1])
			{
				x[k] = x[k]+1;
				coins = coins +1;
			}
		}
	}
	cout << coins;
}


#include <iostream>
using namespace std;
int n,b,b1;
int sky =0;
int money = 0;

int main()
{
	cin >> n;
	int badge[n-1];
	for(int a = 0; a < n; a++)
	{
		cin >> badge[a];
	}

	for(b =0; b < n;)
	{
		sky = 0;
		for(b1 = 0; b1 < n; b1++)
		{
			if(b1 == b)
			{
				b1++;
			}
			if(badge[b] == badge[b1])
			{
				badge[b] = badge[b] + 1;
				money = money +1;
				sky = 1;
			}
		}
		if(sky == 0)
		{
			b++;
		}
	}
	cout << money;
}


#include <iostream>
using namespace std;

int main()
{
	int x[1000];
	int amt;
	int swap;
	int coins = 0;
	int chill = 0;
	cin >> amt;
	for(int a =0; a < amt; a++)
	{
		cin >> x[a];
	}
	for(int h = 0; h < amt-1; h++)
	{
		for(int i = 0; i < amt-1; i++)
		{
			if(x[i] < x[i+1])
			{
				swap = x[i];
				x[i] = x[i+1];
				x[i+1] = swap;
			}
		}
	}
	for(int j = 0; j < amt -1; j++)
	{

		for(int k = 0; k < amt-1; k++)
		{
			if(x[k] == x[k+1])
			{
				x[k] = x[k]+1;
				coins = coins +1;
			}
		}
	}
	cout << coins;
}


#include <iostream>
using namespace std;

int main()
{
	int x[1000];
	int amt;
	int swap;
	int coins = 0;
	cin >> amt;
	for(int a =0; a < amt; a++)
	{
		cin >> x[a];
	}
	for(int h = 0; h < amt-1; h++)
	{
		for(int i = 0; i < amt-1; i++)
		{
			if(x[i] < x[i+1])
			{
				swap = x[i];
				x[i] = x[i+1];
				x[i+1] = swap;
			}
		}
	}
	for(int j = 0; j < amt -1; j++)
	{
		for(int k = 0; k < amt-1; k++)
		{
			if(x[k] == x[k+1])
			{
				x[k+1] = x[k+1]+1;
				coins = coins +1;
			}
		}
	}

	for(int b = 0; b < amt; b++)
	{
		cout << x[b];
	}
}


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


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


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


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


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


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


//not mine
//testing

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

int main()
{
    int n,cost;
    cost=0;
    cin >> n;
    int cfs[n];
    for(int i=0;i<n;i++)
    {
        cin>>cfs[i];
    }

    sort(cfs,cfs+n);
    for (int i=0;i<n;i++)
    {
        if(cfs[i] == cfs [i+1] && i+1<n)
        {
            cfs[i+1]=cfs[i+1]+1;
            cost++;
            sort(cfs,cfs+n);
        }
        if(cfs[i] == cfs [i-1] && i-1>=0)
        {
            cfs[i]=cfs[i]+1;
            cost++;
            sort(cfs,cfs+n);
        }

        for(int k =0;k<=i+1;k++)
        {
            if(cfs[k] == cfs [k+1] && k+1<n)
            {
                cfs[k+1]=cfs[k+1]+1;
                cost++;
                sort(cfs,cfs+n);
            }
            if(cfs[k] == cfs [k-1] && k-1>=0)
            {
                cfs[k]=cfs[k]+1;
                cost++;
                sort(cfs,cfs+n);
            }
        }

    }
    cout << cost << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr[3000];

int main (){
    int n,x,ans=0;
    cin>>n;
    vector <int> v;
    for (int i=0; i<n; i++){
        cin>>x;
        arr[x]++;
    }

    for (int i=0; i<=3000; i++){
        while (arr[i]>1){
            v.push_back(i);
            arr[i]--;
        }
        if (!arr[i])
        for (int j=0; j<v.size(); j++)
            if (v[j]!=-1){
                ans+=i-v[j];
                v[j]=-1;
                break;
            }

    }
    cout<<ans;

}


//not mine
//testing

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

int main()
{
    int n,cost;
    cost=0;
    cin >> n;
    int cfs[n];
    for(int i=0;i<n;i++)
    {
        cin>>cfs[i];
    }

    sort(cfs,cfs+n);
    for (int i=0;i<n;i++)
    {
        if(cfs[i] == cfs [i+1] && i+1<n)
        {
            cfs[i+1]=cfs[i+1]+1;
            cost++;
            sort(cfs,cfs+n);
        }
        if(cfs[i] == cfs [i-1] && i-1>=0)
        {
            cfs[i]=cfs[i]+1;
            cost++;
            sort(cfs,cfs+n);
        }

        for(int k =0;k<=i;k++)
        {
            if(cfs[k] == cfs [k+1] && k+1<n)
            {
                cfs[k+1]=cfs[k+1]+1;
                cost++;
                sort(cfs,cfs+n);
            }
            if(cfs[k] == cfs [k-1] && k-1>=0)
            {
                cfs[k]=cfs[k]+1;
                cost++;
                sort(cfs,cfs+n);
            }
        }
        sort (cfs,cfs+n);
        for (int i=0; i<n; i++)
            cout<<cfs[i]<<" ";
        cout<<endl;
    }
    cout << cost << endl;
    return 0;
}


//not mine
//testing

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

int main()
{
    int n,cost;
    cost=0;
    cin >> n;
    int cfs[n];
    for(int i=0;i<n;i++)
    {
        cin>>cfs[i];
    }

    sort(cfs,cfs+n);
    for (int i=0;i<n;i++)
    {
        if(cfs[i] == cfs [i+1] && i+1<n)
        {
            cfs[i+1]=cfs[i+1]+1;
            cost++;
            sort(cfs,cfs+n);
        }
        if(cfs[i] == cfs [i-1] && i-1>=0)
        {
            cfs[i]=cfs[i]+1;
            cost++;
            sort(cfs,cfs+n);
        }

        for(int k =0;k<=i;k++)
        {
            if(cfs[k] == cfs [k+1] && k+1<n)
            {
                cfs[k+1]=cfs[k+1]+1;
                cost++;
                sort(cfs,cfs+n);
            }
            if(cfs[k] == cfs [k-1] && k-1>=0)
            {
                cfs[k]=cfs[k]+1;
                cost++;
                sort(cfs,cfs+n);
            }
        }
        sort (cfs,cfs+n);

    }
    cout << cost << endl;
    return 0;
}


//not mine
//testing

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

int main()
{
    int n,cost;
    cost=0;
    cin >> n;
    int cfs[n];
    for(int i=0;i<n;i++)
    {
        cin>>cfs[i];
    }

    sort(cfs,cfs+n);
    for (int i=0;i<n;i++)
    {
        if(cfs[i] == cfs [i+1] && i+1<n)
        {
            cfs[i+1]=cfs[i+1]+1;
            cost++;
            sort(cfs,cfs+n);
        }
        if(cfs[i] == cfs [i-1] && i-1>=0)
        {
            cfs[i]=cfs[i]+1;
            cost++;
            sort(cfs,cfs+n);
        }

        for(int k =0;k<=i+1;k++)
        {
            if(cfs[k] == cfs [k+1] && k+1<n)
            {
                cfs[k+1]=cfs[k+1]+1;
                cost++;
                sort(cfs,cfs+n);
            }
            if(cfs[k] == cfs [k-1] && k-1>=0)
            {
                cfs[k]=cfs[k]+1;
                cost++;
                sort(cfs,cfs+n);
            }
        }
        sort (cfs,cfs+n);
        for (int i=0; i<n; i++)
            cout<<cfs[i]<<" ";
        cout<<endl;
    }
    cout << cost << endl;
    return 0;
}


//not mine
//testing

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

int main()
{
    int n,cost;
    cost=0;
    cin >> n;
    int cfs[n];
    for(int i=0;i<n;i++)
    {
        cin>>cfs[i];
    }
    sort(cfs,cfs+n);
    for (int i=0;i<n;i++)
    {
        if(cfs[i] == cfs [i+1] && i+1<n)
        {
            cfs[i+1]=cfs[i+1]+1;
            cost++;
            sort(cfs,cfs+n);
        }
        if(cfs[i] == cfs [i-1] && i-1>=0)
        {
            cfs[i]=cfs[i]+1;
            cost++;
            sort(cfs,cfs+n);
        }

        for(int k =0;k<i;k++)
        {
            if(cfs[k] == cfs [k+1] && k+1<n)
            {
                cfs[k+1]=cfs[k+1]+1;
                cost++;
                sort(cfs,cfs+n);
            }
            if(cfs[k] == cfs [k-1] && k-1>=0)
            {
                cfs[k]=cfs[k]+1;
                cost++;
                sort(cfs,cfs+n);
            }
        }
    }
    cout << cost << endl;
    return 0;
}


//not mine
//testing

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int x,y[3000],sum=0,s2=0,m,mini;
cin>>x;
for(int i=1;i<=x;i++)
{
cin>>y[i];
s2=s2+y[i];
}
sort(y,y+x);

for(int j=y[1];j<x+y[1];j++)
{
sum=sum+j;

}
cout<<endl;
m=sum-s2;
cout<<m<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main (){
    int n,arr[3000],sum1=0,sum2=0;
    cin>>n;
    for (int i=0; i<n; i++){
        cin>>arr[i];
        sum1+=arr[i];
    }

    sort (arr,arr+n);

    // 2 2 2
    // 2 3 2
    // 2 3 2

    //2
    //2 2 2
    // 2 3 3

    // el answer hyb2a el sum bta3 el awl - sum bta3 el array el gdid

    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++)
        if (arr[i]==arr[j] && i!=j){
            arr[j]+=1;
        }
        sum2+=arr[i];

    }

    cout<<sum2-sum1;

}


#include <bits/stdc++.h>

using namespace std;

int arr[60001];

int main (){
    int n,x,ans=0;
    cin>>n;
    vector <int> v;
    for (int i=0; i<n; i++){
        cin>>x;
        arr[x]++;
    }

    for (int i=0; i<=60000; i++){
        while (arr[i]>1){
            v.push_back(i);
            arr[i]--;
        }
        if (!arr[i])
        for (int j=0; j<v.size(); j++)
            if (v[j]!=-1){
                ans+=i-v[j];
                v[j]=-1;
                break;
            }

    }
    cout<<ans;

}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t+1);
int res=0;
for(int i=1;i<=t;i++){
    if(arr[i]<=i)
        res+=i-arr[i];
        }
cout<<res<<endl;
return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t);
int res=0;
for(int i=1;i<=t;i++){
    if(arr[i]<=i)
        res+=i-arr[i];
        }
cout<<res<<endl;
return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t+1);
int res=0;
for(int i=1;i<=t;i++){
    if(arr[i]<=i)
        res+=i-arr[i]
        }
cout<<res<<endl;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<n;i++)
cin>>arr[i+1];

sort(arr+1,arr+t);
int res=0;
for(int i=1;i<=n;i++){
    if(arr[i]<=i)
        res+=i-arr[i];
        }
cout<<res<<endl;
return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t+1);
int res=0,temp=arr[1];

for(int i=2;i<=t;i++){
        if(temp >= arr[i])
            ++temp;
        if(temp < arr[i] )
            temp=arr[i];
        res+=abs(temp-arr[i]);
}

cout<<res<<endl;
return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t+1);
int res=0,temp=arr[1];

for(int i=2;i<=t;i++){
        if(temp >= arr[i])
            arr[i]=(++temp);
        }
        if(temp < arr[i] )
        {
            temp=arr[i];
        }
        res+=abs(temp-arr[i]);
}

cout<<res<<endl;
return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t+1);
int res=0,temp=arr[1];

for(int i=2;i<=t;i++){
        if(temp>=arr[i])
            arr[i]=++temp;
        }
        if(temp<arr[i])
        {
            temp=arr[i];
        }
        res+=abs(temp-arr[i]);
}

cout<<res<<endl;
return 0;
}


By dknight, contest: Codeforces Round #304 (Div. 2), problem: (B) Soldier and Badges, Compilation error, #

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[t+2];
for(int i=0;i<t;i++)
cin>>arr[i+1];

sort(arr+1,arr+t+1);
int res=0;
for(int i=1;i<=t;i++){
    if(arr[i]<=i)
        res+=i-arr[i];
        }
cout<<res<<endl;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
int arr[n+2];
for(int i=0;i<n;i++)
cin>>arr[i+1];

sort(arr+1,arr+n);
int res=0;
for(int i=1;i<=n;i++){
    if(arr[i]<=i)
        res+=i-arr[i];
        }
cout<<res<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,ans,sum=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ans=(n*(n+1))/2;
    ans-=sum;
    if(ans==0)
    cout<<0<<endl;
    else if(ans<0)
    cout<<-1<<endl;
    else
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,ans,sum=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ans=((n*(n+1))/2;
    ans-=sum;
    if(ans==0)
    cout<<0<<endl;
    else
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,ans,sum=0,min1;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    min1=a[0];
    for(i=1;i<n;i++)
    {
        if(min1>a[i])
            min1=a[i];
    }
    ans=((n+min1-1)*(min1+n))/2;
    min1=(min1*(min1-1))/2;
    ans=(ans-sum-min1);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,ans,sum=0,max1,min1;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    max1=a[0];
    min1=a[0];
    for(i=1;i<n;i++)
    {
        if(max1<a[i])
            max1=a[i];
        if(min1>a[i])
            min1=a[i];
    }
    min1--;
    ans=((max1*(max1+1))/2-(min1*(min1+1)/2));
    ans-=sum;
    if(ans<=0)
    cout<<0<<endl;
    else
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int b[3001];
int main()
{
    int n,i,ans=0,j,c,t;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }

    for(i=1;i<=3000;i++)
    {
        j=i+1;
        t=b[i];
        c=0;
        while(t>1)
        {
            c++;
            t--;
            b[j++]++;
            ans+=c;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,ans,sum=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ans=(n*(n+1))/2;
    ans-=sum;
    if(ans==0)
    cout<<0<<endl;
    else
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,ans,sum=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ans=(n*(n+1))/2;
    ans-=sum;
    if(ans<=0)
    cout<<0<<endl;
    else
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int b[6000];
int main()
{
    int n,i,ans=0,j,c,t;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }

    for(i=1;i<=6000;i++)
    {
        j=i+1;
        t=b[i];
        c=0;
        while(t>1)
        {
            c++;
            t--;
            b[j++]++;
            ans+=c;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int b[6000];
int main()
{
    int n,i,ans=0,j,c,t,s=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }

    for(i=1;i<=6000;i++)
    {
        j=i+1;
        t=b[i];
        s+=t;
        c=0;
        while(t>1)
        {
            c++;
            t--;
            b[j++]++;
            ans+=c;
        }
        if(s==n)
            break;
    }
    cout<<ans<<endl;
    return 0;
}


///This  code is created by Samar Singh Holkar
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include<list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define sd(x) scanf("%d",&x)
#define sfd(x) scanf("%d",&x)
#define sfld(x) scanf("%lld",&x
#define pf printf

#define LL long long
#define ll long long
#define LD long double
#define ld long double
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define vi vector<int>
#define fr(i,n) for( int i=0; i<=n; i++)
#define frm(i,m,n) for(int i=m; i<=n; i++)
#define N 200000

int main(){

    int n,count=0; cin>>n;

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

    int brr[n];

    sort(arr,arr+n);

    for(int i=1;i<n;i++){

        if(arr[i]==arr[i-1]){

            arr[i]++;
            count++;
        }

        sort(arr,arr+n);
    }

    cout<<count<<"\n";
}


///This  code is created by Samar Singh Holkar
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include<list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define sd(x) scanf("%d",&x)
#define sfd(x) scanf("%d",&x)
#define sfld(x) scanf("%lld",&x
#define pf printf

#define LL long long
#define ll long long
#define LD long double
#define ld long double
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define vi vector<int>
#define fr(i,n) for( int i=0; i<=n; i++)
#define frm(i,m,n) for(int i=m; i<=n; i++)
#define N 200000

int main(){

    int n,count=0; cin>>n;

    int arr[n],brr[n]; for(int i=0;i<n;i++){cin>>arr[i];brr[i]=arr[i];}

    //int brr[n];

    sort(arr,arr+n);
    sort(brr,brr+n);
    for(int i=1;i<n;i++){

        if(arr[i]==arr[i-1]){

            brr[i]=brr[i-1]+1;
            count++;
        }

        else if(arr[i]==brr[i-1]){

            brr[i]=brr[i-1]+1;
            count++;
        }

        //sort(arr,arr+n);
    }

    //for(int i=0;i<n;i++) cout<<brr[i]<<" ";

    cout<<count<<"\n";
}


///This  code is created by Samar Singh Holkar
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include<list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define sd(x) scanf("%d",&x)
#define sfd(x) scanf("%d",&x)
#define sfld(x) scanf("%lld",&x
#define pf printf

#define LL long long
#define ll long long
#define LD long double
#define ld long double
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define vi vector<int>
#define fr(i,n) for( int i=0; i<=n; i++)
#define frm(i,m,n) for(int i=m; i<=n; i++)
#define N 200000

int main(){

    int n; cin>>n;

    pair<int,int> p[n+10];

    for(int i=0;i<n;i++) {cin>>p[i].first;}

    sort(p,p+n);

    for(int i=0;i<n;i++){p[i].second=i+1;}

    ll ans=0;

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

        ans+=p[i].second-p[i].first;
    }

    cout<<ans<<"\n";
}


///This  code is created by Samar Singh Holkar
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include<list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define sd(x) scanf("%d",&x)
#define sfd(x) scanf("%d",&x)
#define sfld(x) scanf("%lld",&x
#define pf printf

#define LL long long
#define ll long long
#define LD long double
#define ld long double
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define vi vector<int>
#define fr(i,n) for( int i=0; i<=n; i++)
#define frm(i,m,n) for(int i=m; i<=n; i++)
#define N 200000

int main(){

    int n,count=0; cin>>n;

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

    int brr[n];

    sort(arr,arr+n);

    for(int i=1;i<n;i++){

        if(arr[i]==arr[i-1]){

            arr[i]++;
            count++;
        }
    }

    cout<<count<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define Fit(i,c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
//#define mod 1000000007
#define mod 1000
#define sz(a) ((int)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI 2 * acos(0)

#define maxn 500005

int n, a[maxn];
ll res = 0;

int main(){
//  freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    For(i, 1, n) cin >> a[i];
    sort(a + 1, a + n + 1);
    a[0] = 0;
    For(i, 1, n){
        int d = max(a[i - 1] + 1, a[i]);
        res += d - a[i];
        a[i] = d;
    }

    cout << res << endl;

    return 0;
}


///This  code is created by Samar Singh Holkar
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include<list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define sd(x) scanf("%d",&x)
#define sfd(x) scanf("%d",&x)
#define sfld(x) scanf("%lld",&x
#define pf printf

#define LL long long
#define ll long long
#define LD long double
#define ld long double
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define vi vector<int>
#define fr(i,n) for( int i=0; i<=n; i++)
#define frm(i,m,n) for(int i=m; i<=n; i++)
#define N 200000

int main(){

    int n,count=0; cin>>n;

    int arr[n],brr[n]; for(int i=0;i<n;i++){cin>>arr[i];brr[i]=arr[i];}

    //int brr[n];

    sort(arr,arr+n);
    sort(brr,brr+n);
    for(int i=1;i<n;i++){

        if(arr[i]==arr[i-1]){

            brr[i]=brr[i-1]+1;
            count++;
        }

        else if(arr[i]<=brr[i-1]){

            brr[i]=brr[i-1]+1;
            count++;
        }

        //sort(arr,arr+n);
    }

    //for(int i=0;i<n;i++) cout<<brr[i]<<" ";

    cout<<count<<"\n";
}


///This  code is created by Samar Singh Holkar
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include<list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define sd(x) scanf("%d",&x)
#define sfd(x) scanf("%d",&x)
#define sfld(x) scanf("%lld",&x
#define pf printf

#define LL long long
#define ll long long
#define LD long double
#define ld long double
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define vi vector<int>
#define fr(i,n) for( int i=0; i<=n; i++)
#define frm(i,m,n) for(int i=m; i<=n; i++)
#define N 200000

int main(){

    int n; cin>>n;

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

    int brr[n];

    sort(arr,arr+n);

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

        brr[i]=arr[0]+i;
    }
    ll ans=0;
    for(int i=0;i<n;i++){

        ans+=brr[i]-arr[i];
    }

    cout<<ans<<"\n";
}


#include <bits/stdc++.h>
int b[30001];
using namespace std;
int main()
{
    int n,i,p,ans = 0,a;
    cin>>n;
    for(i =1; i <= n; i++){
        cin>>a;
        if(b[a] == 0){
            b[a] =1;
        }else{
            while(b[a]){
                a++;
                ans++;
            }
            b[a] = 1;
        }
    }
    cout<<ans;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999,max;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    for(i = 0; i < n; i++){
        if(b[i] > 1){
            max = b[i] - 1;
        }
    }
    for(i = min; i <= (max + n); i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    for(i = min; i <= n; i++){
        if(b[i] == 1){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999,x;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    x = (2 * n) - 1;
    for(i = min; i <= max; i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    int min = 9999,x;
    int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    x = ((2 * n) - 2);
    for(i = min; i <= x; i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
   // system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    for(i = min; i <= 2 * n; i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999,max = 0;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    for(i = 1; i <= n; i++){
        if(b[i] > 1){
            max = max + b[i] - 1;
        }
    }
    for(i = min; i <= (max + n); i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999,max = 0;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    max = (2 * n) - 2;
    for(i = min; i <= max; i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    for(i = 1; i <= n; i++){
        if(b[i] == 1){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
   // system("pause");
    return 0;
}


#include <bits/stdc++.h>
int b[3001];
using namespace std;
int main()
{
    int n,i,p,ans = 0,a;
    cin>>n;
    for(i =1; i <= n; i++){
        cin>>a;
        if(b[a] == 0){
            b[a] =1;
        }else{
            while(b[a]){
                a++;
                ans++;
            }
            b[a] = 1;
        }
    }
    cout<<ans;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[3001];
using namespace std;
int main()
{
    int n,i,p;
    long int min = 99999,x;
    long int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    x = (2 * n) - 1;
    for(i = min; i <= x; i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>
int a[3001],b[30001];
using namespace std;
int main()
{
    int n,i,p;
    int min = 9999,x;
    int cost = 0;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < min)
        min = a[i];
        b[a[i]] = b[a[i]] + 1;
    }
    x = ((2 * n) - 2);
    for(i = min; i <= x; i++){
        if(b[i] == 1 || b[i] == 0){
            continue;
        }else {
            p = b[i] - 1;
            b[i + 1] = b[i + 1] + p;
            cost =  cost + p;
        }
    }
    cout<<cost<<endl;
   // system("pause");
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
long long n, S;
long long a[3001],i,k,x,t;
int main()
{
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
		cout<<a[i];

	S=0;
   for(i=2;i<=n;i++)
   {
	   if(a[i]<=a[i-1])
		   {
		S=S+a[i-1]-a[i]+1;
	   a[i]=a[i-1]+1;}
	}

cout<<S;
    return 0;
}


#include <iostream>
using namespace std;
long long n, S;
long long a[3001],i,k,x,t;
int main()
{
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a[i];
	}
	sort(a,a+n);

	S=0;
   for(i=2;i<=n;i++)
   {
	   if(a[i]<=a[i-1])
		   {
		S=S+a[i-1]-a[i]+1;
	   a[i]=a[i-1]+1;}
	}

cout<<S;
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
long long n, S;
long long a[3001],i,k,x,t;
int main()
{
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a[i];
	}
	sort(a+1,a+n+1);

	S=0;
   for(i=2;i<=n;i++)
   {
	   if(a[i]<=a[i-1])
		   {
		S=S+a[i-1]-a[i]+1;
	   a[i]=a[i-1]+1;}
	}

cout<<S;
    return 0;
}


#include <iostream>
using namespace std;
long long n, i,S,a;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        S+=a;
    }
    cout<<max(n*1LL*(n+1)/2-S,0LL);
    return 0;
}


#include <iostream>
using namespace std;
long long n, i,S=0,a;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        S=S+a;
    }
    cout<<n*(n+1)/2-S;
    return 0;
}


#include <iostream>
using namespace std;
long long n, S;
long long a[3001],i,k,x,t;
int main()
{
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>x;
        a[x]++;
		S=S+x;
	}

if(a[1]!=0&&a[n]==1)
	S=n*(n+1)/2-S;
else
{
	S=0;k=0;
   for(i=1;i<=2*n;i++)
   {
	  if(a[i]!=0)
		{ k=k+a[i]-1;
		  S=S+k*(k+1)/2;
		  }
	}
}
cout<<S;
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
long long n, S;
long long a[3001],i,k,x,t;
int main()
{
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a[i];
	}
	sort(a,a+n);

	S=0;
   for(i=2;i<=n;i++)
   {
	   if(a[i]<=a[i-1])
		   {
		S=S+a[i-1]-a[i]+1;
	   a[i]=a[i-1]+1;}
	}

cout<<S;
    return 0;
}


#include <iostream>
using namespace std;
long long n, i,S=0,a;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        S=S+a;
    }
    cout<<max(n*1LL*((n+1)/2)-S,0LL);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y=0,cnt=0,z=0,l=0;
cin>>x;
x=static_cast<const int>(x);
long long arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int j=0;j<x;j++){
    for(int i=0;i<x;i++){
            if(j!=i){
            if(arr[j]==arr[i]){
            cnt++;
            arr[i]++;
        }
            }
    }
    sort(arr,arr+x);
}
    cout<<cnt;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y,cnt=0;
cin>>x;
x=static_cast<const int>(x);
int arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int i=0;i<x;i++){
    if(arr[i]==arr[i+1]){
        y=i+1;
        break;
    }
}
inc:
    arr[y]++;

    for(int i=y+1;i<x;i++){
            if(arr[y]==arr[i]){
                    cnt++;
                goto inc;
        }
    }
    cout<<cnt+1;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y=0,cnt=0;
cin>>x;
x=static_cast<const int>(x);
long long arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int i=0;i<x;i++){
    if(arr[i]==arr[i+1]){
        y=i+1;
        break;
    }
}
if(y==0){
    cout<<"0";
}
else{
inc:
    arr[y]++;
    cnt++;

    for(int i=y+1;i<x;i++){
            if(arr[y]==arr[i]){
                goto inc;
        }
    }
    cout<<cnt;
}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y=0,cnt=0;
cin>>x;
x=static_cast<const int>(x);
long long arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int i=0;i<x;i++){
    if(arr[i]==arr[i+1]){
        y=i+1;
        break;
    }
}
if(y==0){
    cout<<"0";
}
else{
inc:
    arr[y]++;

    for(int i=y+1;i<x;i++){
            if(arr[y]==arr[i]){
                cnt++;
                goto inc;
        }
    }
    cout<<cnt+1;
}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y=0,cnt=0;
cin>>x;
x=static_cast<const int>(x);
int arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int i=0;i<x;i++){
    if(arr[i]==arr[i+1]){
        y=i+1;
        break;
    }
}
if(y==0){
    cout<<"0";
}
else{
inc:
    arr[y]++;

    for(int i=y+1;i<x;i++){
            if(arr[y]==arr[i]){
                    cnt++;
                goto inc;
        }
    }
    cout<<cnt+1;
}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y=0,cnt=0;
cin>>x;
x=static_cast<const int>(x);
long long arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int i=0;i<x;i++){
    if(arr[i]==arr[i+1]){
        y=i+1;
        break;
    }
}
if(y==0){
    cout<<"0";
}
else{
inc:
    arr[y]++;
    cnt++;

    for(int i=0;i<x;i++){
            if(i!=y){
            if(arr[y]==arr[i]){
                goto inc;
        }
            }
    }
    cout<<cnt;
}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
int x,y,z=0,cnt=0;
cin>>x;
x=static_cast<const int>(x);
int arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
for(int i=0;i<x;i++){
   for(int j=0;j<x;j++){
    if(i!=j){
        if(arr[i]==arr[j]){
            y=i;
            break;
        }
    }
   }
   if(z!=0){
    break;
   }
}
inc:
    arr[y]++;

    for(int i=0;i<x;i++){
        if(i!=y){
            if(arr[y]==arr[i]){
                    cnt++;
                goto inc;
            }
        }
    }
    cout<<cnt+1;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y=0,cnt=0,z=0;
cin>>x;
x=static_cast<const int>(x);
long long arr[x];
for(int i=0;i<x;i++){
    cin>>arr[i];
}
sort(arr,arr+x);
for(int i=0;i<x;i++){
    if(arr[i]==arr[i+1]){
        y=i;
        z++;
        break;
    }
}
if(z==0){
    cout<<"0";
}
else{
inc:
    arr[y]++;
    cnt++;

    for(int i=y+2;i<x;i++){
            if(arr[y]==arr[i]){
                goto inc;
        }
    }
    cout<<cnt;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[(n*2)+1],x,count=0;
	int i,j;
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
	    cin>>x;
	    a[x]+=1;
    }
    for(i=1;i<=n;i++)
    {
    	if(a[i]>1)
    	{
    	for(j=i+1;j<=2*n && a[i]!=1;j++)
    	{
    		if(a[j]==0)
    		{
    			a[j]=1;
    			count=count+abs(j-i);
    			a[i]-=1;
			}
		}
        }
	}
	cout<<count<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int i,count=0;
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			a[i]+=1;
			count+=1;
		}
		sort(a,a+n);
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1],x,count=0;
	int i,j;
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
	    cin>>x;
	    a[x]+=1;
    }
    for(i=1;i<=n;i++)
    {
    	if(a[i]>1)
    	{
    	for(j=1;j<=n && a[i]!=1;j++)
    	{
    		if(a[j]==0)
    		{
    			a[j]=1;
    			count=count+abs(j-i);
    			a[i]-=1;
			}
		}
        }
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1],x,count=0;
	int i,j;
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
	    cin>>x;
	    a[x]+=1;
    }
    for(i=1;i<=n;i++)
    {
    	if(a[i]>1)
    	{
    	for(j=i+1;j<=n && a[i]!=1;j++)
    	{
    		if(a[j]==0)
    		{
    			a[j]=1;
    			count=count+abs(j-i);
    			a[i]-=1;
			}
		}
        }
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],x,count=0;
	int i,j;
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
	    cin>>x;
	    a[x-1]+=1;
    }
    for(i=0;i<n-1;i++)
    {
    	if(a[i]>1)
    	{
    		a[i+1]=a[i+1]+(a[i]-1);
    		count+=(a[i]-1);
    		a[i]=1;
		}
	}
	if(a[n-1]==1)
	cout<<count<<endl;
	else
	{
		cout<<count+((a[n-1]*(a[n-1]-1))/2)<<endl;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int i,count=0;
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			a[i]+=1;
			count+=1;
		}
	}
	cout<<count<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int i,count=0;
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=1;i<n;i++)
	{
	if(a[i]==a[i-1])
	{
		a[i]+=1;
		count+=1;
		sort(a,a+n);
		i=0;
	}
    }
	cout<<count<<endl;
}


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

using namespace std;

using std::vector;

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

    for (int k = 0; k < t; k++)
    {
        int n, x;
        cin >> n >> x;

        vector<int> favNums(n);

        for (int i = 0; i < n; i++)
        {
            cin >> favNums[i];
        }

        std::sort(favNums.begin(), favNums.end(), greater<>());

        int jumps = 0;
        int distanceTravelled = 0;
        int remainingDistance = x;

        while (remainingDistance > 0)
        {
            for (int i = 0; i < favNums.size(); i++)
            {
                if (favNums[i] == remainingDistance)
                {
                    distanceTravelled = x;
                    remainingDistance = 0;
                    jumps++;
                    break;
                }
                else
                {
                    double middlePoint = (remainingDistance * 1.0) / 2;
                    if (favNums[i] > (middlePoint - distanceTravelled))
                    {
                        distanceTravelled = x;
                        remainingDistance = 0;
                        jumps += 2;
                        break;
                    }
                    else
                    {
                        distanceTravelled += favNums[i];
                        remainingDistance -= favNums[i];
                        jumps++;
                    }
                }
            }
        }

        cout << jumps << endl;
    }

    return 0;
}


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

using namespace std;

using std::vector;

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

    for (int k = 0; k < t; k++)
    {
        int n, x;
        cin >> n >> x;

        vector<int> favNums(n);

        for (int i = 0; i < n; i++)
        {
            cin >> favNums[i];
        }

        std::sort(favNums.begin(), favNums.end(), greater<int>());

        int jumps = 0;
        int distanceTravelled = 0;
        int remainingDistance = x;

        while (remainingDistance > 0)
        {
            if (remainingDistance <= favNums[0])
            {
                for (int i = 0; i < favNums.size(); i++)
                {
                    if (favNums[i] == remainingDistance)
                    {
                        distanceTravelled = x;
                        remainingDistance = 0;
                        jumps++;
                        break;
                    }
                    else if (favNums[i] < remainingDistance)
                    {
                        break;
                    }
                }
            }

            if (remainingDistance == 0)
            {
                break;
            }
            else
            {
                double middlePoint = (remainingDistance * 1.0) / 2;
                if (favNums[0] > (middlePoint - distanceTravelled))
                {
                    distanceTravelled = x;
                    remainingDistance = 0;
                    jumps += 2;
                    break;
                }
                else
                {
                    distanceTravelled += favNums[0];
                    remainingDistance -= favNums[0];
                    jumps++;
                }
            }
        }

        cout << jumps << endl;
    }

    return 0;
}


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

using namespace std;

using std::vector;

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

    for (int k = 0; k < t; k++)
    {
        int n, x;
        cin >> n >> x;

        vector<int> favNums(n);

        for (int i = 0; i < n; i++)
        {
            cin >> favNums[i];
        }

        std::sort(favNums.begin(), favNums.end(), greater<int>());

        int jumps = 0;
        int distanceTravelled = 0;
        int remainingDistance = x;

        while (remainingDistance > 0)
        {
            for (int i = 0; i < favNums.size(); i++)
            {
                if (favNums[i] == remainingDistance)
                {
                    distanceTravelled = x;
                    remainingDistance = 0;
                    jumps++;
                    break;
                }
                else
                {
                    double middlePoint = (remainingDistance * 1.0) / 2;
                    if (favNums[i] > (middlePoint - distanceTravelled))
                    {
                        distanceTravelled = x;
                        remainingDistance = 0;
                        jumps += 2;
                        break;
                    }
                    else
                    {
                        distanceTravelled += favNums[i];
                        remainingDistance -= favNums[i];
                        jumps++;
                    }
                }
            }
        }

        cout << jumps << endl;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

using std::vector;

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

    for (int k = 0; k < t; k++)
    {
        int n, x;
        cin >> n >> x;

        vector<int> favNums(n);

        for (int i = 0; i < n; i++)
        {
            cin >> favNums[i];
        }

        std::sort(favNums.begin(), favNums.end(), greater<int>());

        if (find(favNums.begin(), favNums.end(), x) != favNums.end())
        {
            cout << 1 << endl;
        }
        else
        {
            cout << max(2, (int)ceil((1.0 * x) / favNums[0])) << endl;
        }
    }

    return 0;
}


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

using namespace std;

using std::vector;

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

    for (int k = 0; k < t; k++)
    {
        int n, x;
        cin >> n >> x;

        vector<int> favNums(n);

        for (int i = 0; i < n; i++)
        {
            cin >> favNums[i];
        }

        std::sort(favNums.begin(), favNums.end(), greater<int>());

        int jumps = 0;
        int distanceTravelled = 0;
        int remainingDistance = x;

        while (remainingDistance > 0)
        {
            if (remainingDistance <= favNums[0])
            {
                for (int i = 0; i < favNums.size(); i++)
                {
                    if (favNums[i] == remainingDistance)
                    {
                        distanceTravelled = x;
                        remainingDistance = 0;
                        jumps++;
                        break;
                    }
                }
            }

            if (remainingDistance == 0)
            {
                break;
            }
            else
            {
                double middlePoint = (remainingDistance * 1.0) / 2;
                if (favNums[0] > (middlePoint - distanceTravelled))
                {
                    distanceTravelled = x;
                    remainingDistance = 0;
                    jumps += 2;
                    break;
                }
                else
                {
                    distanceTravelled += favNums[0];
                    remainingDistance -= favNums[0];
                    jumps++;
                }
            }
        }

        cout << jumps << endl;
    }

    return 0;
}


//
//  main.cpp
//  aazzz
//
//  Created by Alex Zhou on 6/8/20.
//  Copyright  2020 Alex Zhou. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i = 0; i<n; i++) {
        int a,x;
        cin>>a>>x;
        int b[a];
        for (int j = 0; j<a; j++) {
            int temp;
            cin>>temp;
            if (temp>x) {
                temp=x/2;
            }
            b[j]=temp;
        }
        sort(b,b+a,greater<int>());
        int max=b[0];
        if (x%max==0) {
            cout<<x/max<<endl;
        }else{
            cout<<x/max+1<<endl;
        }
    }
    return 0;
}


//
//  main.cpp
//  aazzz
//
//  Created by Alex Zhou on 6/8/20.
//  Copyright  2020 Alex Zhou. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i = 0; i<n; i++) {
        int a,x;
        cin>>a>>x;
        int b[a];
        for (int j = 0; j<a; j++) {
            int temp;
            cin>>temp;
            if (temp>x) {
                temp=0;
            }
            b[j]=temp;
        }
        sort(b,b+a,greater<int>());
        int max=b[0];
        if (x%max==0) {
            cout<<x/max<<endl;
        }else{
            cout<<x/max+1<<endl;
        }
    }
    return 0;
}


//
//  main.cpp
//  aazzz
//
//  Created by Alex Zhou on 6/8/20.
//  Copyright  2020 Alex Zhou. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i = 0; i<n; i++) {
        long long a,x;
        cin>>a>>x;
        long long b[a];
        for (int j = 0; j<a; j++) {
            long long temp;
            cin>>temp;
            if (temp>x) {
                temp=x/2+1;
            }
            b[j]=temp;
        }
        sort(b,b+a,greater<int>());
        long long max=b[0];
        if (x%max==0) {
            cout<<x/max<<endl;
        }else{
            cout<<x/max+1<<endl;
        }
    }
    return 0;
}


//
//  main.cpp
//  aazzz
//
//  Created by Alex Zhou on 6/8/20.
//  Copyright  2020 Alex Zhou. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i = 0; i<n; i++) {
        long long a,x;
        cin>>a>>x;
        long long b[a];
        long long temp1=2;
        long long ans=999999999;
        for (int j = 0; j<a; j++) {
            long long temp;
            cin>>temp;
            if (temp>x) {
                ans=min(ans,temp1 );
            }
            else if (x%temp==0) {
                ans=min(ans,x/a);
            }else{
                ans=min(ans,x/a+1);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


//
//  main.cpp
//  aazzz
//
//  Created by Alex Zhou on 6/8/20.
//  Copyright  2020 Alex Zhou. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i = 0; i<n; i++) {
        long long a,x;
        cin>>a>>x;
        long long b[a];
        long long temp1=2;
        long long ans=999999999;
        for (int j = 0; j<a; j++) {
            long long temp;
            cin>>temp;
            if (temp>x) {
                ans=min(ans,temp1);
            }
            else if (x%temp==0) {
                ans=min(ans,x/temp);
            }else{
                ans=min(ans,x/temp+1);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


//
//  main.cpp
//  aazzz
//
//  Created by Alex Zhou on 6/8/20.
//  Copyright  2020 Alex Zhou. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i = 0; i<n; i++) {
        long long a,x;
        cin>>a>>x;
        long long b[a];
        long long temp1=2;
        long long ans=9999999999;
        for (int j = 0; j<a; j++) {
            long long temp;
            cin>>temp;
            if (temp>x) {
                ans=min(ans,temp1);
            }
            else if (x%temp==0) {
                ans=min(ans,x/temp);
            }else{
                ans=min(ans,x/temp+1);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    int arr[100005];

    scanf("%d", &t);

    while(t--) {

        int n, x;

        int ans = INT_MAX;

        scanf("%d %d", &n, &x);

        bool flag = false;

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

            scanf("%d", &arr[i]);

            if(arr[i] == x) {

                printf("1\n");

                flag = true;

                break;

            }

        }

        sort(arr, arr + n);

        if(flag) continue;

        printf("%d\n", max(2, (x + arr[n - 1] - 1)/arr[n - 1]));

    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {

    long long int t;

    scanf("%lld", &t);

    while(t--) {

    	long long int n, x, temp, maxs = -1;

    	bool flag = false;

        scanf("%lld %lld", &n, &x);

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

            scanf("%lld", &temp);

            if(temp == x && flag == false) {

                printf("1\n");

                flag = true;

            }

            maxs = max(temp, maxs);

        }

        if(flag) continue;

        else printf("%lld\n", max((long long)2, (x + maxs - 1)/maxs));

    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    int arr[100005];

    scanf("%d", &t);

    while(t--) {

        int n, x;

        int ans = INT_MAX;

        scanf("%d %d", &n, &x);

        bool flag = false;

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

            scanf("%d", &arr[i]);

            if(arr[i] == x) {

                printf("1\n");

                flag = true;

                break;

            }

            ans = min(ans,  (x + arr[i] - 1)/arr[i]);

        }

        if(flag) continue;

        printf("%d\n", max(2, ans));

    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    scanf("%d", &t);

    while(t--) {

    	int n, x, temp, maxs = 0;

        bool flag = false;

        scanf("%d %d", &n, &x);

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

            scanf("%d", &temp);

            if(temp == x) {

                printf("1\n");

                flag = true;

                break;

            }

            maxs = max(temp, maxs)

        }

        if(flag) continue;

        printf("%d\n", max(2, maxs));

    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    scanf("%d", &t);

    while(t--) {

    	int arr[100005];

        int n, x;

        int ans = INT_MAX;

        scanf("%d %d", &n, &x);

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

            scanf("%d", &arr[i]);

        }

        sort(arr, arr + n);

        int low = 0;

        int high = n - 1;

        while(low <= high) {

            int mid = (low + high)/2;

            if(arr[mid] > x) {

            	high = mid - 1;

            	ans = 2;
            } else {

                ans = min(ans, (x + arr[mid] - 1)/arr[mid]);

                low = mid + 1;

            }

        }

        printf("%d\n", ans);

    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    scanf("%d", &t);

    while(t--) {

    	int n, x, temp, maxs = -1;

    	bool flag = false;

        scanf("%d %d", &n, &x);

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

            scanf("%d", &temp);

            if(temp == x) {

                printf("1\n");

                flag = true;

                break;

            }

            maxs = max(temp, maxs);

        }

        if(flag) continue;

        printf("%d\n", max(2, (x + maxs - 1)/maxs));

    }

}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t;

    scanf("%d", &t);

    while(t--) {

    	int n, x, temp, maxs = 0;

        scanf("%d %d", &n, &x);

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

            scanf("%d", &temp);

            if(temp == x) {

                printf("1\n");

                flag = true;

                break;

            }

            maxs = max(temp, maxs)

        }

        if(flag) continue;

        printf("%d\n", max(2, maxs));

    }

}


// I want to AC

#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
//#define  ll long long
using namespace std;
const int maxn = 1e6+7;
const int N = 1e5+10;

#define FOR(i, x, y) for (ll i = (x), _##i = (y); i < _##i; ++i)

ll mod = 1e9+7;
//const int maxn = 100010;
//ll f[maxn];
//ll inv[maxn]; // 阶乘的逆元
//void CalFact()
//{
//    f[0] = 1;
//    for (int i = 1; i < maxn; i++) f[i] = (f[i - 1] * i) % p;
//    inv[maxn - 1] = Pow(f[maxn - 1], p - 2, p);
//    for (int i = maxn - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % p;
//}
//ll C(int n, int m) { return f[n] * inv[m] % p * inv[n - m] % p; }

//int h[N], e[N] , ne[N], idx ;
//int depth[N], fa[N][16];
//int qu[N];
//vector <int > g[N];
//void add(int a , int b ){
//    h[idx] = b;
//    ne[idx] = h[a];
//    h[a] =idx++;
//}
//void dfs(int root){
//    for(int i=0;i<g[root].size();i++){
//            int v = g[root][i];
//            if(v== fa[root][0])continue ;
//            fa[v][0] = root ;
//            depth[v] = depth[root]+1 ;
//            dfs(v);
//    }
//
//
//}
//void bfs(int root)
//{
//    memset(depth, 0x3f, sizeof depth);
//    depth[0] = 0, depth[root] = 1;
//    int hh = 0, tt = 0;
//    qu[0] = root;
//    while (hh <= tt)
//    {
//        int t = qu[hh ++ ];
//        for (int i = h[t]; ~i; i = ne[i])
//        {
//            int j = e[i];
//            if (depth[j] > depth[t] + 1)
//            {
//                depth[j] = depth[t] + 1;
//                qu[ ++ tt] = j;
//                fa[j][0] = t;
//                for (int k = 1; k <= 16; k ++ )
//                    fa[j][k] = fa[fa[j][k - 1]][k - 1];
//            }
//        }
//    }
//}
//
//int lca(int a, int b)
//{
//    if (depth[a] < depth[b]) swap(a, b);
//    for (int k = 15; k >= 0; k -- )
//        if (depth[fa[a][k]] >= depth[b])
//            a = fa[a][k];
//    if (a == b) return a;
//    for (int k = 16; k >= 0; k -- )
//        if (fa[a][k] != fa[b][k])
//        {
//            a = fa[a][k];
//            b = fa[b][k];
//        }
//    return fa[a][0];
//}
//
//int dis ( int x, int y )
//{
//    return depth[x] + depth[y] - depth[lca(x,y)]* 2;
//
//}
//bool check ( int x , int y){
//    return y>=x  &&x%2 == y%2 ;
//}
int t;
int ar[maxn];
int main() {
    cin >>t;
    while(t--){
        int n,x ;
        cin >>n>>x;
        for(int i=0;i<n;i++)cin>>ar[i];
        sort(ar, ar+n);
//        cout<<ar[0]<<endl;
int sum = 0x7f7f7f;int pos =0 ;
        for(int i=n-1;i>=0;i--){
            if(ar[i]< x )
                {
                    if(sum > x/ar[i])sum = x/ar[i] , pos = i;
                    else if(sum == x/ar[i]  && x%ar[i]==0 &&sum ==1 )pos = i;

                }
            else if(ar[i] >=x ) sum = 1, pos = i;
        }
        if (( x %ar[pos]==0))cout<<sum<<endl;
        else cout<<sum+1<<endl;
//        cout<<n<<endl;
    }
	return 0;

}


// I want to AC

#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
//#define  ll long long
using namespace std;
const int maxn = 1e6+7;
const int N = 1e5+10;

#define FOR(i, x, y) for (ll i = (x), _##i = (y); i < _##i; ++i)

ll mod = 1e9+7;
//const int maxn = 100010;
//ll f[maxn];
//ll inv[maxn]; // 阶乘的逆元
//void CalFact()
//{
//    f[0] = 1;
//    for (int i = 1; i < maxn; i++) f[i] = (f[i - 1] * i) % p;
//    inv[maxn - 1] = Pow(f[maxn - 1], p - 2, p);
//    for (int i = maxn - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % p;
//}
//ll C(int n, int m) { return f[n] * inv[m] % p * inv[n - m] % p; }

//int h[N], e[N] , ne[N], idx ;
//int depth[N], fa[N][16];
//int qu[N];
//vector <int > g[N];
//void add(int a , int b ){
//    h[idx] = b;
//    ne[idx] = h[a];
//    h[a] =idx++;
//}
//void dfs(int root){
//    for(int i=0;i<g[root].size();i++){
//            int v = g[root][i];
//            if(v== fa[root][0])continue ;
//            fa[v][0] = root ;
//            depth[v] = depth[root]+1 ;
//            dfs(v);
//    }
//
//
//}
//void bfs(int root)
//{
//    memset(depth, 0x3f, sizeof depth);
//    depth[0] = 0, depth[root] = 1;
//    int hh = 0, tt = 0;
//    qu[0] = root;
//    while (hh <= tt)
//    {
//        int t = qu[hh ++ ];
//        for (int i = h[t]; ~i; i = ne[i])
//        {
//            int j = e[i];
//            if (depth[j] > depth[t] + 1)
//            {
//                depth[j] = depth[t] + 1;
//                qu[ ++ tt] = j;
//                fa[j][0] = t;
//                for (int k = 1; k <= 16; k ++ )
//                    fa[j][k] = fa[fa[j][k - 1]][k - 1];
//            }
//        }
//    }
//}
//
//int lca(int a, int b)
//{
//    if (depth[a] < depth[b]) swap(a, b);
//    for (int k = 15; k >= 0; k -- )
//        if (depth[fa[a][k]] >= depth[b])
//            a = fa[a][k];
//    if (a == b) return a;
//    for (int k = 16; k >= 0; k -- )
//        if (fa[a][k] != fa[b][k])
//        {
//            a = fa[a][k];
//            b = fa[b][k];
//        }
//    return fa[a][0];
//}
//
//int dis ( int x, int y )
//{
//    return depth[x] + depth[y] - depth[lca(x,y)]* 2;
//
//}
//bool check ( int x , int y){
//    return y>=x  &&x%2 == y%2 ;
//}
int t;
int ar[maxn];
int main() {
    cin >>t;
    while(t--){
        int n,x ;
        cin >>n>>x;
        for(int i=0;i<n;i++)cin>>ar[i];
        sort(ar, ar+n);
//        cout<<ar[0]<<endl;
int sum = 0x7f7f7f;int pos =0 ;
        for(int i=n-1;i>=0;i--){
            if(ar[i]<= x )
               {
                   if(sum >x/ar[i]){
                    sum = x/ar[i]; pos = i;}
                    else if(x %ar[i]==0&& x/ar[i]==1 ) pos = i ;
               }
            else if(ar[i] >x ) sum = min(sum , 1), pos = i;
        }
       // cout<<pos<<endl;
        if ((x >=ar[pos ] && x %ar[pos]==0))cout<<sum<<endl;
        else cout<<sum+1<<endl;
//        cout<<n<<endl;
    }
	return 0;

}