stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <map>

#include <cmath>

#include <algorithm>

#include <functional>

using namespace std;



//素数判定

inline bool IsPrime(int p) {

	if (p == 1) return false;

	for (int i = 2; i <= sqrt(p); i++) {

		if (p%i == 0) return false;

	}

	return true;

}



//10進数の自然数の桁数を返す

inline int GetDigit(int num) {

	return (int)log10(num) + 1;

}



//各位の和を返す

int GetDigitsSum(int num) {

	int N = 0;

	while (num > 0) {

		N += num % 10;

		num /= 10;

	}

	return N;

}







//異なるn個からr個の整数を取り出す組合せの数を求める

int combination(int n, int r) {

	if (r == 0 || n == r) {

		return 1;

	}

	else if (r == 1) {

		return n;

	}

	else {

		return combination(n - 1, r - 1) + combination(n - 1, r);

	}



}



struct MyStruct

{

	int x;

	int no;

	int P;

	int Y;

};



struct city

{

	vector<MyStruct> M;



};



struct ans

{

	int P;

	int x;

	int no;

};



bool cmp(const ans &a, const ans &b)

{

	return a.no < b.no;

}



bool cmpY(const MyStruct &a, const MyStruct &b) {

	return a.Y < b.Y;

}



int main() {

	int N, M;



	vector<city> c(100001);

	vector<ans> AAA;



	cin >> N >> M;

	for (int i = 0; i < M; i++)

	{

		MyStruct tmp;

		cin >> tmp.P >> tmp.Y;

		tmp.no = i;

		c[tmp.P].M.push_back(tmp);

	}



	for (int i = 0; i < 100001; i++)

	{

		sort(c[i].M.begin(), c[i].M.end(),cmpY);

		int n = (int)c[i].M.size();

		int dtx = 1;

		for (int j = 0; j < n; j++)

		{

			c[i].M[j].x = dtx++;

		}



		for (int j = 0; j < n; j++)

		{

			ans A;

			A.no = c[i].M[j].no;

			A.P = c[i].M[j].P;

			A.x = c[i].M[j].x;

			AAA.push_back(A);

		}

	}



	sort(AAA.begin(), AAA.end(), cmp);

	for (int i = 0; i < M; i++)

	{

		printf("%06d%06d\n", AAA[i].P, AAA[i].x);

	}



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.8231540878166106x):
#include <iostream>

#include <string>

#include <vector>

#include <map>

#include <cmath>

#include <algorithm>

#include <functional>

#include <stack>

#include <numeric>

typedef long long ll;

using namespace std;

const int MOD = (int)1e9 + 7;

const ll INF = (ll)1e18 + 7;

//#define int long long



struct MyStr{

	int Y;

	int P;

	int No;

	int X;

};



bool cmp_no(const MyStr &a, const MyStr &b) {

	return a.No < b.No;

}



bool cmp(const MyStr &a, const MyStr &b) {

	if (a.P == b.P) {

		return a.Y < b.Y;

	}

	else {

		return a.P < b.P;

	}

}



signed main() {

	cin.tie(0);

	ios::sync_with_stdio(false);



	int N, M;

	cin >> N >> M;

	vector<MyStr> vec(M);



	for (int i = 0; i < M; i++)

	{

		cin >> vec[i].P >> vec[i].Y;

		vec[i].No = i;

	}



	sort(vec.begin(), vec.end(), cmp);



	int t = 1;

	vec[0].X = 1;

	for (int i = 1; i < M; i++)

	{

		if (vec[i - 1].P != vec[i].P) {

			vec[i].X = 1;

			t = 1;

		}

		else {

			vec[i].X = ++t;

		}

	}



	sort(vec.begin(), vec.end(), cmp_no);



	for (int i = 0; i < M; i++)

	{

		printf("%06d%06d\n", vec[i].P,vec[i].X);

	}



	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



vector<vector<int>> group((100001), vector<int>(0, 0));



int getNumber(int n, int left, int right, int target) {

	int mid = (left + right) / 2;

	while(true) {

		mid = (left + right) / 2;

		if (group.at(n).at(mid) == target) {

			return mid;

		}

		else if (group.at(n).at(mid) < target) {

			left = mid + 1;

		}

		else {

			right = mid - 1;

		}

	}

} 



int main(){

    int n,m;

	cin >> n >> m;

	vector<int> p(m),y(m);

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

		cin >> p.at(i) >> y.at(i);

		group.at(p.at(i)).push_back(y.at(i));

	}

    

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

		sort(group.at(i).begin(),group.at(i).end());

	}

	

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

		cout << setfill('0') << setw(6) << right << p.at(i) << setfill('0') << setw(6) << right << getNumber(p.at(i), 0, group.at(p.at(i)).size() - 1, y.at(i)) + 1 << endl;

	}

}


// Faster C++ solution for the same problem (measured speedup: 3.5723925401033227x):
#include <algorithm>

#include <cmath>

#include <complex>

#include <iostream>

#include <map>

#include <queue>

#include <set>

#include <vector>

#include <functional>

#include <cstring>



using namespace std;



#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)



using ll = long long;

using P = pair<int, int>;



const long long MOD = 1e9+7;



template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



template<class T>

istream& operator >>(istream &is, vector<T> &v) {

    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);

    return is;

}



int main() {

    int n, m;

    cin >> n >> m;

    using tpl = tuple<int, int, int>;

    vector<tpl> x(m + 1);

    x[0] = tpl(-1, -1, -1);

    vector<P> number(m);

    rep(i, m) {

        int p, y;

        cin >> p >> y;

        x.at(i + 1) = tpl(p, y, i);

    }

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

    

    int num = 1;

    rep(i, m) {

        int p, y, nm;

        tie(p, y, nm) = x.at(i + 1);

        if (get<0>(x.at(i)) != p) num = 1;

        else num++;

        number.at(nm) = P(p, num);

    }

    

    rep(i, m) {

        int p = number.at(i).first, nm = number.at(i).second;

        printf("%06d%06d\n", p, nm);

    }

}
// Slower C++ solution:
#include <cstdio>

#include <vector>

#include <algorithm>

#include <iostream>



using namespace std;

typedef long long ll;



int main() {

		int N, M;

		int P[100000], Y[100000];

		vector<int> yd[100001];



		cin >> N >> M;

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

				cin >> P[i] >> Y[i];

				yd[P[i]].push_back(Y[i]);

		}



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

				sort(yd[i+1].begin(), yd[i+1].end());

		}



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

				printf("%012lld\n", ll(P[i])*1000000 + int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin()) + 1);

		}

		

		return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5615639776003047x):
#include <iostream>

#include <cstdio>

#include <vector>

#include <algorithm>



using namespace std;



typedef long long ll;



int main() {

		int N, M;

		cin >> N >> M;

		vector<int> P(M, 0), Y(M, 0);

		vector<int> d[N + 1];

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

				cin >> P[i] >> Y[i];

				d[P[i]].push_back(Y[i]);

		}



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

				sort (d[i].begin(), d[i].end());

		}



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

				printf( "%012lld\n", ll(P[i]) * 1000000 + (int)(lower_bound(d[P[i]].begin(), d[P[i]].end(), Y[i]) - d[P[i]].begin()) + 1 );

		}

		

		return 0;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<algorithm>

#include<map>

#include<cstring>

#include<math.h>

#include<bitset>

#include<queue>

#include<set>

#include<iomanip>

#include<math.h>

// #include<bits/stdc++.h>

using namespace std;

#define ll long long

constexpr long long int INFLL = 1001001001001001LL;

constexpr int INFI = 1000000007;



int main(){

  int N,M;

  cin >> N >> M;

  vector<int> P(1000000),Y(1000000);

  vector<int> yd[100001];

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

    cin >> P[i] >> Y[i];

    yd[P[i]].push_back(Y[i]);

  }

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

    sort(yd[i+1].begin(),yd[i+1].end());

  }

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

    cout << setfill('0') << right << setw(6) << P[i];

    cout << setfill('0') << right << setw(6) << lower_bound(yd[P[i]].begin(),yd[P[i]].end(),Y[i])-(yd[P[i]].begin())+1 << endl;

  }

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 11.953813332535647x):
#include<iostream>

#include<vector>

#include<algorithm>

#include<map>

#include<cstring>

#include<math.h>

#include<bitset>

#include<queue>

#include<set>

#include<iomanip>

#include<math.h>

#include<assert.h>

#include<string>

#include<cstdlib>

#include<cctype>

#include<unordered_map>

#include<sstream>

#include<numeric>

#include<stack>

// #include<bits/stdc++.h>

using namespace std;

using ll = long long;

using P = pair<int,int>;

constexpr ll INF = 1LL<<60;

const double INFD = 1e100;

const ll mod = 1000000007;

const double PI = 3.1415926535897932384626433832795028841971;

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};

template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

};

template<class T> inline bool chmax(T& a, T b) {

    if (a < b) {

        a = b;

        return true;

    }

    return false;

};



// intやllをstringに変換

template<typename T> inline string toString(const T &a){

  ostringstream oss;

  oss << a;

  return oss.str();

};

// ----------------------------------------------------------------------------



int main(){

  int N,M;

  cin >> N >> M;

  vector<vector<int>> G(N);

  vector<P> id(M);

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

    int P,Y;

    cin >> P >> Y;

    P--;

    G[P].push_back(Y);

    id[i] = make_pair(P,Y);

  }

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

    sort(G[i].begin(),G[i].end());

  }

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

    id[i].second = lower_bound(G[id[i].first].begin(),G[id[i].first].end(),id[i].second) - G[id[i].first].begin();

  }

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

    cout << setfill('0') << right << setw(6) << id[i].first+1;

    cout << setfill('0') << right << setw(6) << id[i].second+1 << endl;

  }

  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#define f first

#define s second

using namespace std;



typedef pair<pair<long,long>,pair<long,long> > pp;



bool ppc(pp& f,pp& s){return f.s.s<s.s.s;}



int main()

{

	int n,m,p,y;

	cin>>n>>m;

	pp a[100010];

	for(int i=1;i<=m;i++)

	{

		cin>>p>>y;

		a[i].f.f=p;

		a[i].f.s=y;

		a[i].s.f=0;

		a[i].s.s=i;

	}

	sort(a+1,a+m+1);

	p=a[1].f.f;

	y=1;

	for(int i=1;i<=m;i++)

	{

		if(p!=a[i].f.f)p=a[i].f.f,y=1;

		a[i].s.f=y;

		y++;

	}

	sort(a+1,a+m+1,ppc);

	for(int i=1;i<=m;i++)

	{

		printf("%012ld\n",a[i].f.f*1000000l+a[i].s.f);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6280036819221555x):
#include<iostream>

#include<cstdio>

#include<algorithm>

#define f first

#define s second

using namespace std;



typedef pair<pair<int,int>,pair<int,int> > P;



bool PC(P& f,P& s){return f.s.s<s.s.s;}



int main()

{

	int n,m,p,y;

	P a[100010];

	cin>>n>>m;

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

	{

		cin>>p>>y;

		a[i].f.f=p;

		a[i].f.s=y;

		a[i].s.f=0;

		a[i].s.s=i;

	}

	sort(a,a+m);

	p=a[0].f.f;

	y=0;

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

	{

		if(p!=a[i].f.f)p=a[i].f.f,y=0;

		a[i].s.f=++y;

	}

	sort(a,a+m,PC);

	for(int i=0;i<m;i++)printf("%012ld\n",(long)(a[i].f.f*1e6+a[i].s.f));

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<iomanip>

#include<vector>

#include<algorithm>

using namespace std;



int main(){

  int N,M;

  cin >> N >> M;

  int P[100000];

  int Y[100000];

  vector<int>Y_num[100001];



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

	cin >> P[i] >> Y[i];

	Y_num[P[i]].push_back(Y[i]);	

  }



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

	sort(Y_num[i+1].begin(),Y_num[i+1].end());

  }

  

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

	cout << setw(6) << setfill('0')<<P[i];

	cout << setw(6) << setfill('0')<<int(lower_bound(Y_num[P[i]].begin(),Y_num[P[i]].end(),Y[i])-Y_num[P[i]].begin())+1;



	cout << endl;

  }

  





  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5478243950767063x):
#include<iostream>

#include<iomanip>

#include<vector>

#include<algorithm>

using namespace std;



int main(){

  int N,M;

  cin >> N >> M;

  int P[M+1];

  int Y[M+1];

  vector<int>Y_num[N+1];

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

	cin >> P[i] >> Y[i];

	Y_num[P[i]].push_back(Y[i]);	

  }



  for(int i=0;i<N+1;i++){	

	sort(Y_num[i].begin(),Y_num[i].end());

  }

  

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

	cout << setw(6) << setfill('0')<<P[i];

	cout << setw(6) << setfill('0')<<int(lower_bound(Y_num[P[i]].begin(),Y_num[P[i]].end(),Y[i])-Y_num[P[i]].begin())+1;



	cout << endl;

  }

  

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main(){

    int n,m;

    cin>>n>>m;

    int p[100000],y[100000];

    vector<int> v[100001];

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

        cin>>p[i]>>y[i];

        v[p[i]].push_back(y[i]);

    }

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

        sort(v[i].begin(),v[i].end());

    }

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

        cout<<setfill('0')<<setw(6)<<p[i];

        cout<<setfill('0')<<setw(6);

        cout<<lower_bound(v[p[i]].begin(),v[p[i]].end(),y[i])-v[p[i]].begin()+1<<endl;

    }

}


// Faster C++ solution for the same problem (measured speedup: 3.595038643252226x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MOD=1e9+7;

const int INF=1e9;



int main(){

    int n,m;

    cin>>n>>m;

    vector<int> v[n];

    int p[m],y[m];

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

        cin>>p[i]>>y[i];

        v[--p[i]].push_back(y[i]);

    }

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

        sort(v[i].begin(),v[i].end());

        //v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());

    }

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

        int t=lower_bound(v[p[i]].begin(),v[p[i]].end(),y[i])-v[p[i]].begin();

        printf("%06d%06d\n",p[i]+1,t+1);

    }

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(n);i++)

#define ALL(v) (v).begin(),(v).end()

#define int long long

using namespace std;

typedef vector<int>   vint;

typedef pair<int,int> pint;



const int SZ=100005;

set<int> st[SZ];

pint id[SZ];

map<int,int> year_to_idx;



signed main()

{

    int N,M;

    cin>>N>>M;

    REP(i,M){

        int p,y; cin>>p>>y;

        year_to_idx[y]=i;

        st[p-1].insert(y);

    }



    REP(p,N){

        if(st[p].size()==0) continue;

        int cnt=1;

        for(auto y:st[p]){

            int idx=year_to_idx[y];

            id[idx].first=p+1;

            id[idx].second=cnt;

            cnt++;

        }

    }



    REP(i,M){

        printf("%06lld%06lld\n",id[i].first,id[i].second);

    }



}


// Faster C++ solution for the same problem (measured speedup: 1.7965668431119675x):
#include<bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(n);i++)

#define ALL(v) (v).begin(),(v).end()

#define int long long

using namespace std;

typedef vector<int>   vint;

typedef pair<int,int> pint;



const int SZ=100005;



vector<pint> v[SZ];

pint id[SZ];



signed main()

{

    int N,M;

    cin>>N>>M;



    REP(i,M){

        int p,y; cin>>p>>y;

        v[p-1].push_back(pint(y,i));

    }

    

    REP(i,N){

        if(v[i].empty()) continue;

        sort(ALL(v[i]));

        REP(j,v[i].size()){

            int idx=v[i][j].second;

            id[idx]=pint(i+1,j+1);

        }

    }

    

    REP(i,M){

        printf("%06lld%06lld\n",id[i].first,id[i].second);

    }



}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int N, M;

int P[100005], Y[100005];

vector<int> yd[100005];

int main()

{

  cin >> N >> M;

  for (int i = 0; i < M; i++)

  {

    cin >> P[i] >> Y[i];

    yd[P[i]].push_back(Y[i]);

  }

  for (int i = 0; i < N; i++)

    sort(yd[i + 1].begin(), yd[i + 1].end());

  for (int i = 0; i < M; i++)

  {

    printf("%06d", P[i]);

    printf("%06d\n", lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin() + 1);

  }



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5185883684660264x):
#include <bits/stdc++.h>

using namespace std;

#define rep(i, m, n) for (int i = m; i < n; ++i)



int main() {

  int N, M;

  cin >> N >> M;

  vector<int> P(M), Y(M);

  vector<vector<int>> A(N + 1,vector<int>());

  rep(i, 0, M) {

    cin >> P[i] >> Y[i];

    A[P[i]].push_back(Y[i]);

  }

  rep(i, 1, N + 1) sort(A[i].begin(), A[i].end());

  rep(i, 0, M) {

    int n = lower_bound(A[P[i]].begin(), A[P[i]].end(), Y[i]) - A[P[i]].begin();

    printf("%06d%06d\n", P[i], n + 1);

  }

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <vector>

#include <algorithm>

using namespace std;

typedef long long ll;

#define rep(i,n) for (int i=0; i<n; i++)

int N , M;

int P [100000] , Y [100000];

vector < int > yd [100001];





int main ()

{

scanf("%d%d", &N, &M);

rep(i, M) scanf("%d%d", &P[i], &Y[i]), yd[P[i]].push_back(Y[i]);

rep(i, N) sort(yd[i+1].begin(), yd[i+1].end());

rep(i, M) printf("%012lld\n" , ll(P[i])*1000000+ int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin())+1);

}

// Faster C++ solution for the same problem (measured speedup: 3.3920295896253907x):
#include <iostream>

#include<sstream>

#include<string>

#include<vector>

#include <cmath>

#include <limits>

#include <queue>

#include<algorithm>

#include <map>

#include <stack>

#include <iomanip>

#include <cstdio>





using namespace std;

 

#define rep(i,n) for (int (i)=0;(i)<(n);i++)





/*int binarySearch(vector<int > v, int target){

  int l = 0, r = v.size();

  int mid;

  while (l+1<r){

    mid = (r+l)/2;

    if (v[mid] <= target){

      l = mid;

    }

    else r = mid;

  }

  return l;

}*/





int main(){

  int n, m;

  cin >> n >> m;

  int p[m];

  int y[m];

  vector<int> id[n];

  rep(i,m){

    scanf("%d%d", &p[i], &y[i]), id[p[i]-1].push_back(y[i]);

  }

  rep(i,n){

    sort(id[i].begin(),id[i].end());

  }



  int res;

  rep(i,m){

    res = lower_bound(id[p[i]-1].begin(), id[p[i]-1].end(), y[i])-id[p[i]-1].begin();

    cout<< setfill('0') << setw(6)  << p[i];

    cout << setfill('0') << setw(6)  << res+1 << endl;

  }  

  return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iomanip>

#include <ios>

#include <iostream>

using namespace std;

const int MAX = 100000;



int main() {

  int N, M, P, Y;

  cin >> N >> M;

  pair<pair<int, int>, int> city[MAX];

  pair<int, int> ans[MAX];

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

    cin >> P >> Y;

    city[i] = make_pair(make_pair(P, Y), i);

  }

  sort(city, city + M);

  for (int i = 0, c = 1; i < M;

       i++, c = i < M && city[i - 1].first.first == city[i].first.first ? c + 1

                                                                        : 1)

    ans[city[i].second] = make_pair(city[i].first.first, c);



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

    cout << setfill('0') << right << setw(6) << ans[i].first;

    cout << setfill('0') << right << setw(6) << ans[i].second;

    cout << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.9619436053184924x):
#include <bits/stdc++.h>



using namespace std;

using pii = pair<int, int>;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N, M;

  cin >> N >> M;

  vector<vector<pii>> PY(N + 1);

  vector<pii> res(M);

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

    int p, y;

    cin >> p >> y;

    PY[p].push_back(make_pair(y, i));

  }

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

    if (PY[i].size() == 0)

      continue;

    sort(PY[i].begin(), PY[i].end());

    for (int j = 0; j < PY[i].size(); j++)

      res[PY[i][j].second] = make_pair(i, j + 1);

  }

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

    cout << setfill('0') << right << setw(6) << res[i].first;

    cout << setfill('0') << right << setw(6) << res[i].second << '\n';

  }

  return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iomanip>

#include <ios>

#include <iostream>

using namespace std;

const int MAX = 100000;



int main() {

  int N, M, P, Y;

  cin >> N >> M;

  pair<pair<int, int>, int> city[MAX];

  pair<int, int> ans[MAX];

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

    cin >> P >> Y;

    city[i] = make_pair(make_pair(P, Y), i);

  }

  sort(city, city + M);

  for (int i = 0, c = 1; i < M;

       i++, c = i < M && city[i - 1].first.first == city[i].first.first ? c + 1

                                                                        : 1)

    ans[city[i].second] = make_pair(city[i].first.first, c);



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

    cout << setfill('0') << right << setw(6) << ans[i].first;

    cout << setfill('0') << right << setw(6) << ans[i].second;

    cout << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.9592923451412507x):
#include <bits/stdc++.h>



using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N, M;

  cin >> N >> M;

  vector<int> P(M), Y(M);

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

    cin >> P[i] >> Y[i];

  }



  map<int, int> cnt;

  vector<int> idx(M);

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

    idx[i] = i;

  }

  sort(idx.begin(), idx.end(), [&](int a, int b) { return Y[a] < Y[b]; });



  vector<pair<int, int>> res(M);

  for (auto i : idx) {

    res[i] = make_pair(P[i], cnt[P[i]]++);

  }



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

    cout << setfill('0') << right << setw(6) << res[i].first << setw(6)

         << res[i].second + 1 << '\n';

  }

  return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iomanip>

#include <ios>

#include <iostream>

using namespace std;

const int MAX = 100000;



int main() {

  int N, M, P, Y;

  cin >> N >> M;

  pair<pair<int, int>, int> city[MAX];

  pair<int, int> ans[MAX];

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

    cin >> P >> Y;

    city[i] = make_pair(make_pair(P, Y), i);

  }

  sort(city, city + M);

  for (int i = 0, c = 1; i < M;

       i++, c = i < M && city[i - 1].first.first == city[i].first.first ? c + 1

                                                                        : 1)

    ans[city[i].second] = make_pair(city[i].first.first, c);



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

    cout << setfill('0') << right << setw(6) << ans[i].first;

    cout << setfill('0') << right << setw(6) << ans[i].second;

    cout << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.962737216118219x):
#include <bits/stdc++.h>



using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int N, M;

  cin >> N >> M;

  vector<int> P(M), Y(M);

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

    cin >> P[i] >> Y[i];

  }

  vector<int> idx(M);

  iota(idx.begin(), idx.end(), 0);

  sort(idx.begin(), idx.end(), [&](int a, int b) { return Y[a] < Y[b]; });

  vector<int> cnts(N + 1, 0);



  vector<pair<int, int>> res(M);



  for (auto i : idx) {

    res[i] = make_pair(P[i], cnts[P[i]]++);

  }



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

    cout << setfill('0') << right << setw(6) << res[i].first;

    cout << setfill('0') << right << setw(6) << res[i].second + 1;

    cout << '\n';

  }

  return 0;

}