Problem:
Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq P_i \leq N

1 \leq Y_i \leq 10^9

Y_i are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Sample Input 1

2 3
1 32
2 63
1 12

Sample Output 1

000001000002
000002000001
000001000001

As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.

As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.

As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

2 3
2 55
2 77
2 99

Sample Output 2

000002000001
000002000002
000002000003

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)


#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue() {
  int a;
  cin >> a;
  return a;
};
void inputVector(vector<int>* v) {
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  int a;
  while (cin >> a) {
    if (a == -1)break;
    v->push_back(a);
  }
};

void inputVector(vector<int> * p, int a) {
  rep(i, a) {
    int input;
    cin >> input;
    p->push_back(input);
  }
}

void inputVector2(vector<vector<int>>& v, int r, int c) {
  int temp;
  for (size_t i = 0; i < r; i++)
  {
    for (size_t j = 0; j < c; j++)
    {
      scanf("%d", &temp);
      v[i][j] = temp;
    }
  }
}
void inputVector3(vector<int>* v0, vector<int>* v1) {
  int a;
  unsigned short count = 0b0;
  while (cin >> a) {
    if (a == -1)break;
    if (count)v0->push_back(a); else v1->push_back(a);
    count = count ^ 1;
  }
};

template <typename T>
void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  }
  else {
    cout << a << "\n";
  }
}

void outid(int p, int num) {
  int keta = 6;
  string ps;
  string nums;
  string id;
  ostringstream sout01;
  ostringstream sout02;
  sout01 << std::setfill('0') << std::setw(keta) << p;
  sout02 << std::setfill('0') << std::setw(keta) << num;
  ps = sout01.str();
  nums = sout02.str();
  id = ps + nums;
  cout << id << endl;
}

int main(int argc, const char * argv[]) {
  int n;
  int m;

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

  vector<vector<int>> inputs;
  auto city = vector<vector<int>> (n+1);

  {
    int a, b;
    while (cin >> a) {
      if (a == -1)break;
      cin >> b;
      inputs.emplace_back();
      inputs.back().push_back(a);
      inputs.back().push_back(b);
      city[a].push_back(b);
    }
  }

  for (auto& cities : city) {
    sort(cities.begin(), cities.end());
  }

  for (size_t i = 0; i < inputs.size(); i++)
  {
    vector<int>::iterator it;
    int num;
    it = find(city[inputs[i][0]].begin(), city[inputs[i][0]].end(), inputs[i][1]);
    num = it - city[inputs[i][0]].begin() + 1;
    outid(inputs[i][0], num);
  }
}