prithivMLmods/Coder-Stat huggingface dataset:
Problem p03221 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = map(int, input().split())
pys = [list(map(int, input().split())) for _ in range(m)]
map_ = {}
for i, (p, y) in enumerate(pys):
    map_.setdefault(p, [])
    for j in range(len(map_[p])):
        if y < pys[map_[p][j]][1]:
            map_[p].insert(j, i)
            break
    else:
        map_[p].append(i)
ans = [None] * m
for key, val in map_.items():
    for num, i in enumerate(val):
        ans[i] = "{:06d}".format(key) + "{:06d}".format(num + 1)
for a in ans:
    print(a)


Fixed submission:
n, m = map(int, input().split())
pys = [list(map(int, input().split())) for _ in range(m)]
map_ = {}
for i, (p, y) in enumerate(pys):
    map_.setdefault(p, [])
    map_[p].append(i)

for val in map_.values():
    val.sort(key=lambda i: pys[i][1])

ans = [None] * m
for key, val in map_.items():
    for num, i in enumerate(val):
        ans[i] = "{:06d}".format(key) + "{:06d}".format(num + 1)
for a in ans:
    print(a)
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define pb push_back
#define mp make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 30)
#define LLINF (1 << 60)
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

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

  int n, m;
  int p[10000], y[10000];
  vector<int> yd[10001];
  cin >> n >> m;
  rep(i, m) {
    cin >> 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);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define pb push_back
#define mp make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 30)
#define LLINF (1 << 60)
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

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

  int n, m;
  int p[100000], y[100000];
  vector<int> yd[100001];
  cin >> n >> m;
  rep(i, m) {
    cin >> 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);
  return 0;
}
Problem p03221 (Python)

Buggy submission (status: Runtime Error):
import collections

City = collections.namedtuple("City", ("number", "pref", "year"))

n, m = [int(i) for i in input().split()]
cities = []
for i in range(m):
    pref, year = input().split()
    city = City(i, int(pref), int(year))
    cities.append(city)
id_numbers = []
cities.sort(key=lambda x: x.year)
cities.sort(key=lambda x: x.pref)
prev_pref = None
for city in cities:
    if prev_pref is None or city.pref != prev_pref:
        rank = 1
    else:
        rank += 1
    id_numbers.append((city.number, city.pref, rank))
    prev_pref = city.pref
id_numbers.sort(key=lambda x: x[0])
for i in id_numbers:
    print(f"{i[1]:0>6}{i[2]:0>6}")


Fixed submission:
import collections

City = collections.namedtuple("City", ("number", "pref", "year"))

n, m = [int(i) for i in input().split()]
cities = []
for i in range(m):
    pref, year = input().split()
    city = City(i, int(pref), int(year))
    cities.append(city)
id_numbers = []
cities.sort(key=lambda x: x.year)
cities.sort(key=lambda x: x.pref)
prev_pref = None
for city in cities:
    if prev_pref is None or city.pref != prev_pref:
        rank = 1
    else:
        rank += 1
    id_numbers.append((city.number, city.pref, rank))
    prev_pref = city.pref
id_numbers.sort(key=lambda x: x[0])
for i in id_numbers:
    print("{:0>6}{:0>6}".format(i[1], i[2]))
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
/* *
 *
 * Author: Hamkor
 *
 * */

#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<pair<int, int>>
#define VLL vector<pair<ll, ll>>
#define PB push_back()
#define B begin()
#define E end()
#define F first
#define S second
#define SZ size()
#define P complex<ll>
#define X real()
#define Y imag()
const int oo = 1e9;
const ll mod = 1e7;
/* * * *   * * *   	* * * */

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n + 1, vector<int>());
  VI p(n + 1), y(m + 1);
  for (int i = 0; i < m; ++i) {
    cin >> p[i] >> y[i];
    a[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; ++i)
    sort(a[i].B, a[i].E);
  for (int i = 0; i < m; ++i) {
    cout << right << setw(6) << setfill('0') << p[i];
    int j = lower_bound(a[p[i]].B, a[p[i]].E, y[i]) - a[p[i]].B + 1;
    cout << right << setw(6) << setfill('0') << j << "\n";
  }
  return 0;
}


Fixed submission:
/* *
 *
 * Author: Hamkor
 *
 * */

#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<pair<int, int>>
#define VLL vector<pair<ll, ll>>
#define PB push_back()
#define B begin()
#define E end()
#define F first
#define S second
#define SZ size()
#define P complex<ll>
#define X real()
#define Y imag()
const int oo = 1e9;
const ll mod = 1e7;
/* * * *   * * *   	* * * */

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n + 1, vector<int>());
  VI p(1e5 + 10), y(1e5 + 10);
  for (int i = 0; i < m; ++i) {
    cin >> p[i] >> y[i];
    a[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; ++i)
    sort(a[i].B, a[i].E);
  for (int i = 0; i < m; ++i) {
    cout << right << setw(6) << setfill('0') << p[i];
    int j = lower_bound(a[p[i]].B, a[p[i]].E, y[i]) - a[p[i]].B + 1;
    cout << right << setw(6) << setfill('0') << j << "\n";
  }
  return 0;
}
Problem p03221 (Python)

Buggy submission (status: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print(f"{p:06}{rank:06}")


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print("{:06}{:06}".format(p, rank))
Problem p03221 (Python)

Buggy submission (status: Runtime Error):
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[p[i]]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))


Fixed submission:
N, M = [int(i) for i in input().split(" ")]
p = list()
y = list()
yd = {}
for i in range(0, M):
    pi, yi = [int(i) for i in input().split(" ")]
    p.append(pi)
    y.append(yi)
    if pi in yd.keys():
        yd[pi].append(yi)
    else:
        yd[pi] = [yi]

ydid = {}
for i in yd.keys():
    num = 1
    for j in sorted(yd[i]):
        ydid[j] = num
        num = num + 1

for i in range(0, M):
    print("{:06}{:06}".format(p[i], ydid[y[i]]))
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int64_t INF = 1'000'000'000'000'000;
int64_t N, ans;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int64_t> P(M), Y(M);
  for (int i = 0; i < M; i++)
    cin >> P[i] >> Y[i];

  vector<vector<int64_t>> sorted(N, vector<int64_t>());
  for (int i = 0; i < M; i++) {
    sorted[P[i] - 1].push_back(Y[i]);
    sort(sorted[P[i] - 1].begin(), sorted[P[i] - 1].end());
  }

  for (int i = 0; i < M; i++) {
    printf("%012lld\n", (int64_t)(P[i] * 1000000 +
                                  lower_bound(sorted[P[i] - 1].begin(),
                                              sorted[P[i] - 1].end(), Y[i]) -
                                  sorted[P[i] - 1].begin() + 1));
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int64_t INF = 1'000'000'000'000'000;
int64_t N, ans;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int64_t> P(M), Y(M);
  for (int i = 0; i < M; i++)
    cin >> P[i] >> Y[i];

  vector<vector<int64_t>> sorted(N, vector<int64_t>());
  for (int i = 0; i < M; i++) {
    sorted[P[i] - 1].push_back(Y[i]);
  }
  for (int i = 0; i < N; i++) {
    sort(sorted[i].begin(), sorted[i].end());
  }

  for (int i = 0; i < M; i++) {
    printf("%012lld\n", (int64_t)(P[i] * 1000000 +
                                  lower_bound(sorted[P[i] - 1].begin(),
                                              sorted[P[i] - 1].end(), Y[i]) -
                                  sorted[P[i] - 1].begin() + 1));
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1 << 29;
typedef long long int ll;

struct fuck {
  int y;
  int p;
  int rank;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> a(N + 2);
  vector<fuck> F(N + 2);
  rep(i, M) {
    cin >> F[i].p >> F[i].y;
    --F[i].p;
    a[F[i].p].push_back(pair<int, int>(F[i].y, i));
  }
  rep(i, N) {
    if (!a[i].empty())
      sort(a[i].begin(), a[i].end());
  }
  rep(i, N) {
    if (!a[i].empty()) {
      int k = 1;
      for (pair<int, int> j : a[i]) {
        F[j.second].rank = k;
        ++k;
      }
    }
  }
  rep(i, M) {
    cout << setw(6) << setfill('0') << F[i].p + 1 << setw(6) << setfill('0')
         << F[i].rank << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1 << 29;
typedef long long int ll;

struct fuck {
  int y;
  int p;
  int rank;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> a(N);
  vector<fuck> F(M);
  rep(i, M) {
    cin >> F[i].p >> F[i].y;
    --F[i].p;
    a[F[i].p].push_back(pair<int, int>(F[i].y, i));
  }
  rep(i, N) {
    if (!a[i].empty())
      sort(a[i].begin(), a[i].end());
  }
  rep(i, N) {
    if (!a[i].empty()) {
      int k = 1;
      for (pair<int, int> j : a[i]) {
        F[j.second].rank = k;
        ++k;
      }
    }
  }
  rep(i, M) {
    cout << setw(6) << setfill('0') << F[i].p + 1 << setw(6) << setfill('0')
         << F[i].rank << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

int main(void) {

  int n, m;
  cin >> n;
  cin >> m;

  vector<int> p(m);
  vector<int> y(m);
  // cout << m << endl;
  for (int i = 0; i < m; i++) {

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

  vector<vector<int>> pre(n + 1, vector<int>(0));

  // cout << pre.size() << endl;
  // cout << pre[0].size() << endl;

  for (int i = 0; i < m; i++) {
    pre[p[i]].push_back(y[i]);
  }
  for (int i = 1; i < n + 1; i++) {
    sort(pre[i].begin(), pre[i].end());
    for (int j = 0; j < pre[i].size(); j++) {
      // cout << pre[i][j] << " ";
    }

    // cout << endl;
  }

  for (int i = 0; i < m; i++) {
    auto itr = find(pre[p[i]].begin(), pre[p[i]].end(), y[i]);
    // cout << distance(pre[p[i]].begin(),itr)+1 << endl;
    auto d = distance(pre[p[i]].begin(), itr) + 1;
    cout << setfill('0') << right << setw(6) << p[i];
    cout << setfill('0') << right << setw(6) << d;
    cout << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

int main(void) {

  int n, m;
  cin >> n;
  cin >> m;

  vector<int> p(m);
  vector<int> y(m);
  // cout << m << endl;
  for (int i = 0; i < m; i++) {

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

  vector<vector<int>> pre(n + 1, vector<int>(0));

  // cout << pre.size() << endl;
  // cout << pre[0].size() << endl;

  for (int i = 0; i < m; i++) {
    pre[p[i]].push_back(y[i]);
  }
  for (int i = 1; i < n + 1; i++) {
    sort(pre[i].begin(), pre[i].end());
    for (int j = 0; j < pre[i].size(); j++) {
      // cout << pre[i][j] << " ";
    }

    // cout << endl;
  }

  for (int i = 0; i < m; i++) {
    // auto itr = find(pre[p[i]].begin(),pre[p[i]].end(),y[i]);
    auto itr = lower_bound(pre[p[i]].begin(), pre[p[i]].end(), y[i]);
    // cout << distance(pre[p[i]].begin(),itr)+1 << endl;
    auto d = distance(pre[p[i]].begin(), itr) + 1;
    cout << setfill('0') << right << setw(6) << p[i];
    cout << setfill('0') << right << setw(6) << d;
    cout << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

int cnt[100100];
int ans0[100100];
int ans1[100100];

string get_string(int x) {
  string ans;
  for (int d = 100000; d >= 1; d /= 10) {
    ans += to_string(x / d);
    x -= x / d;
  }
  return ans;
}

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

  vector<tuple<int, int, int>> v;
  for (int city_id = 0; city_id < m; city_id++) {
    int p, y;
    cin >> p >> y;

    v.push_back({p, y, city_id});
  }

  sort(v.begin(), v.end());
  for (auto vv : v) {
    int p = get<0>(vv);
    int city_id = get<2>(vv);

    cnt[p]++;
    ans0[city_id] = p;
    ans1[city_id] = cnt[p];
  }

  for (int city_id = 0; city_id < m; city_id++) {
    string s1 = get_string(ans0[city_id]);
    string s2 = get_string(ans1[city_id]);

    assert(s1.size() == 6 && s2.size() == 6);

    cout << s1 << s2;
    if (city_id + 1 != m)
      cout << '\n';
  }
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

int cnt[100100];
int ans0[100100];
int ans1[100100];

string get_string(int x) {
  string ans;
  for (int d = 100000; d >= 1; d /= 10) {
    ans += to_string(x / d);
    x -= (x / d) * d;
  }
  return ans;
}

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

  vector<tuple<int, int, int>> v;
  for (int city_id = 0; city_id < m; city_id++) {
    int p, y;
    cin >> p >> y;

    v.push_back({p, y, city_id});
  }

  sort(v.begin(), v.end());
  for (auto vv : v) {
    int p = get<0>(vv);
    int city_id = get<2>(vv);

    cnt[p]++;
    ans0[city_id] = p;
    ans1[city_id] = cnt[p];
  }

  for (int city_id = 0; city_id < m; city_id++) {
    string s1 = get_string(ans0[city_id]);
    string s2 = get_string(ans1[city_id]);

    assert(s1.size() == 6 && s2.size() == 6);

    cout << s1 << s2;
    if (city_id + 1 != m)
      cout << '\n';
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<map<int, int>> p(N + 1);
  vector<string> S(N + 1);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    p[a][b] = i;
  }
  for (int i = 1; i <= N; i++) {
    int id = 1;
    for (auto s : p[i]) {
      string tmpl = to_string(i);
      string tmpr = to_string(id);
      reverse(tmpl.begin(), tmpl.end());
      reverse(tmpr.begin(), tmpr.end());
      while (tmpl.size() < 6) {
        tmpl.push_back('0');
      }
      while (tmpr.size() < 6) {
        tmpr.push_back('0');
      }
      reverse(tmpl.begin(), tmpl.end());
      reverse(tmpr.begin(), tmpr.end());
      S[s.second] = tmpl + tmpr;
      id++;
    }
  }
  REP(i, S.size()) { cout << S[i] << "\n"; }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<map<int, int>> p(N + 1);
  vector<string> S(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    p[a][b] = i;
  }
  for (int i = 1; i <= N; i++) {
    int id = 1;
    for (auto s : p[i]) {
      string tmpl = to_string(i);
      string tmpr = to_string(id);
      reverse(tmpl.begin(), tmpl.end());
      reverse(tmpr.begin(), tmpr.end());
      while (tmpl.size() < 6) {
        tmpl.push_back('0');
      }
      while (tmpr.size() < 6) {
        tmpr.push_back('0');
      }
      reverse(tmpl.begin(), tmpl.end());
      reverse(tmpr.begin(), tmpr.end());
      S[s.second] = tmpl + tmpr;
      id++;
    }
  }
  REP(i, S.size()) { cout << S[i] << "\n"; }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M);
  vector<int> Y(M);
  for (int i = 0; i < N; i++) {
    cin >> P[i] >> Y[i];
    P[i]--;
  }

  vector<vector<int>> val(N);
  for (int i = 0; i < M; i++) {
    val[P[i]].push_back(Y[i]);
  }
  for (int j = 0; j < N; j++) {
    sort(val[j].begin(), val[j].end());
  }

  for (int i = 0; i < M; i++) {
    int v = P[i];
    cout << setw(6) << setfill('0') << v + 1;

    int id = lower_bound(val[v].begin(), val[v].end(), Y[i]) - val[v].begin();
    cout << setw(6) << setfill('0') << id + 1 << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M);
  vector<int> Y(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    P[i]--;
  }

  vector<vector<int>> val(N);
  for (int i = 0; i < M; i++) {
    val[P[i]].push_back(Y[i]);
  }
  for (int j = 0; j < N; j++) {
    sort(val[j].begin(), val[j].end());
  }

  for (int i = 0; i < M; i++) {
    int v = P[i];
    cout << setw(6) << setfill('0') << v + 1;

    int id = lower_bound(val[v].begin(), val[v].end(), Y[i]) - val[v].begin();
    cout << setw(6) << setfill('0') << id + 1 << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m), l(m), num(n);
  vector<pair<int, int>> post(m);
  vector<pair<int, int>> city(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    post[i] = make_pair(y[i], p[i]);
    city[i] = make_pair(y[i], i);
  }
  for (int i = 0; i < m; i++)
    num[i] = 0;
  sort(post.begin(), post.end());
  sort(city.begin(), city.end());

  //    for (int i = 0; i < m; i++) cout << city[i].second << "," <<
  //    post[i].second << "," << post[i].first << endl;

  for (int i = 0; i < m; i++) {
    num[post[i].second]++; // 県番号
    l[city[i].second] = num[post[i].second];
  }

  for (int j = 0; j < m; j++) {
    int tmp = 0, pp = p[j];
    while (pp != 0) {
      tmp++;
      pp /= 10;
    }
    for (int i = 0; i < 6 - tmp; i++)
      cout << "0";
    cout << p[j];
    tmp = 0;
    int ll = l[j];
    while (ll != 0) {
      tmp++;
      ll /= 10;
    }
    for (int i = 0; i < 6 - tmp; i++)
      cout << "0";
    cout << l[j] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m), l(m), num(n);
  vector<pair<int, int>> post(m);
  vector<pair<int, int>> city(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    post[i] = make_pair(y[i], p[i]);
    city[i] = make_pair(y[i], i);
  }
  for (int i = 0; i < n; i++)
    num[i] = 0;
  sort(post.begin(), post.end());
  sort(city.begin(), city.end());

  //    for (int i = 0; i < m; i++) cout << city[i].second << "," <<
  //    post[i].second << "," << post[i].first << endl;

  for (int i = 0; i < m; i++) {
    num[post[i].second]++; // 県番号
    l[city[i].second] = num[post[i].second];
  }

  for (int j = 0; j < m; j++) {
    int tmp = 0, pp = p[j];
    while (pp != 0) {
      tmp++;
      pp /= 10;
    }
    for (int i = 0; i < 6 - tmp; i++)
      cout << "0";
    cout << p[j];
    tmp = 0;
    int ll = l[j];
    while (ll != 0) {
      tmp++;
      ll /= 10;
    }
    for (int i = 0; i < 6 - tmp; i++)
      cout << "0";
    cout << l[j] << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define cinf(n, x, y)                                                          \
  for (int i = 0; i < (n); i++)                                                \
    cin >> x[i] >> y[i];
typedef long long int ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    p[i]--;
  }
  vector<vector<int>> pre(n);
  for (int i = 0; i < m; i++)
    pre[p[i]].push_back(y[i]);

  for (int i = 0; i < n; i++)
    sort(pre[i].begin(), pre[i].end());
  for (int i = 0; i < m; i++) {
    int num = p[i];
    printf("%06d", num + 1);

    int id = lower_bound(pre[i].begin(), pre[i].end(), y[i]) - pre[i].begin();
    printf("%06d\n", id + 1);
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define cinf(n, x, y)                                                          \
  for (int i = 0; i < (n); i++)                                                \
    cin >> x[i] >> y[i];
typedef long long int ll;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    p[i]--;
  }
  vector<vector<int>> pre(n);
  for (int i = 0; i < m; i++)
    pre[p[i]].push_back(y[i]);

  for (int i = 0; i < n; i++)
    sort(pre[i].begin(), pre[i].end());
  for (int i = 0; i < m; i++) {
    int num = p[i];
    printf("%06d", num + 1);

    int id =
        lower_bound(pre[num].begin(), pre[num].end(), y[i]) - pre[num].begin();
    printf("%06d\n", id + 1);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(n);
  vector<vector<int>> c(100000, vector<int>());
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    p--;
    v[i] = make_pair(p, y);
    c[p].push_back(y);
  }
  for (int i = 0; i < n; i++)
    sort(c[i].begin(), c[i].end());
  for (int i = 0; i < m; i++) {
    int p = v[i].first;
    int y = find(c[p].begin(), c[p].end(), v[i].second) - c[p].begin();
    p++;
    y++;
    printf("%06d%06d\n", p, y);
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  vector<vector<int>> c(100000, vector<int>());
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    p--;
    v[i] = make_pair(p, y);
    c[p].push_back(y);
  }
  for (int i = 0; i < n; i++)
    sort(c[i].begin(), c[i].end());
  for (int i = 0; i < m; i++) {
    int p = v[i].first;
    int y = find(c[p].begin(), c[p].end(), v[i].second) - c[p].begin();
    p++;
    y++;
    printf("%06d%06d\n", p, y);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  std::vector<int> P(M), Y(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    P[i]--;
  }
  std::vector<map<int, int>> m(N);
  for (int i = 0; i < M; i++)
    m[P[i]][Y[i]] = 0;
  for (int i = 0; i < N; i++) {
    int k = 1;
    for (auto &p : m[P[i]])
      p.second = k++;
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << P[i] + 1;
    cout << setfill('0') << right << setw(6) << m[P[i]][Y[i]] << endl;
  }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  std::vector<int> P(M), Y(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    P[i]--;
  }
  std::vector<map<int, int>> m(N);
  for (int i = 0; i < M; i++)
    m[P[i]][Y[i]] = 0;
  for (int i = 0; i < N; i++) {
    int k = 1;
    for (auto &p : m[i])
      p.second = k++;
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << P[i] + 1;
    cout << setfill('0') << right << setw(6) << m[P[i]][Y[i]] << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {

  int n, m;
  cin >> n >> m;

  int p[m], y[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
  }

  vector<vector<pair<int, int>>> vec_y;
  vec_y.resize(n);

  for (int i = 0; i < m; i++) {
    vec_y[p[i] - 1].push_back(make_pair(y[i], i));
  }
  for (int i = 0; i < n; i++) {
    if (vec_y[i].size() != 0) {
      sort(vec_y[i].begin(), vec_y[i].end());
    }
  }

  vector<tuple<int, int, int>> vec_ans;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < vec_y[i].size(); j++) {
      // cout << vec_y[i][j].first << " " << vec_y[i][j].second << endl;
      vec_ans.push_back(make_tuple(vec_y[i][j].second, p[i], j + 1));
    }
  }

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

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << setw(6) << get<1>(vec_ans[i]);
    cout << setfill('0') << setw(6) << get<2>(vec_ans[i]) << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {

  int n, m;
  cin >> n >> m;

  int p[m], y[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
  }

  vector<vector<pair<int, int>>> vec_y;
  vec_y.resize(n);

  for (int i = 0; i < m; i++) {
    vec_y[p[i] - 1].push_back(make_pair(y[i], i));
  }
  for (int i = 0; i < n; i++) {
    if (vec_y[i].size() != 0) {
      sort(vec_y[i].begin(), vec_y[i].end());
    }
  }

  vector<tuple<int, int, int>> vec_ans;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < vec_y[i].size(); j++) {
      // cout << vec_y[i][j].first << " " << vec_y[i][j].second << endl;
      vec_ans.push_back(make_tuple(vec_y[i][j].second, i + 1, j + 1));
    }
  }

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

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << setw(6) << get<1>(vec_ans[i]);
    cout << setfill('0') << setw(6) << get<2>(vec_ans[i]) << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int32 N, M, K;
vector<int64> A, B;
string s;

double abss(double x) {
  if (x < 0)
    return x * -1;
  return x;
}

int main(void) {
  cin >> N >> M;
  A = vector<int64>(N, 0);
  using T = tuple<int32, int32, int32>;
  vector<T> C(M);
  REP(i, M) {
    int32 a, b, c;
    cin >> b >> a;
    c = i;
    C[i] = T(a, b, c);
  }
  sort(all(C));
  vector<PII> res(M);
  REP(i, M) {
    int32 a, b, c;
    tie(b, a, c) = C[i];
    res[c] = PII(a, (A[a]++) + 1);
  }
  REP(i, M) {
    cout << setw(6) << setfill('0') << res[i].fs << setw(6) << setfill('0')
         << res[i].sc << endl;
  }
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int32 N, M, K;
vector<int64> A, B;
string s;

double abss(double x) {
  if (x < 0)
    return x * -1;
  return x;
}

int main(void) {
  cin >> N >> M;
  A = vector<int64>(N + 1, 0);
  using T = tuple<int32, int32, int32>;
  vector<T> C(M);
  REP(i, M) {
    int32 a, b, c;
    cin >> b >> a;
    c = i;
    C[i] = T(a, b, c);
  }
  sort(all(C));
  vector<PII> res(M);
  REP(i, M) {
    int32 a, b, c;
    tie(b, a, c) = C[i];
    res[c] = PII(a, (A[a]++) + 1);
  }
  REP(i, M) {
    cout << setw(6) << setfill('0') << res[i].fs << setw(6) << setfill('0')
         << res[i].sc << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
// long time no ac
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define repe(i, I1, I2) for (i = I1; i < I2; i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define mod 1000000007

ll cd(ll n) {
  ll count = 0;
  while (n != 0) {
    n = n / 10;
    ++count;
  }
  return count;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k, t, c = 0, i, m, x, y;
  t = 1;
  // cin>>t;

  while (t--) {
    cin >> n >> m;
    vector<pair<ll, pair<ll, ll>>> h(n);
    pair<ll, ll> a[n];
    rep(i, m) {
      cin >> x >> y;
      a[i].first = x;
      a[i].second = y;
      h[i].first = x;
      h[i].second.first = y;
      h[i].second.second = i;
    }
    sort(h.begin(), h.end());
    ll prev = h[0].first;
    rep(i, m) {
      if (h[i].first == prev) {
        c++;
      } else {
        prev = h[i].first;
        c = 1;
      }
      a[h[i].second.second].second = c;
    }
    rep(i, m) {
      x = cd(a[i].first);
      // cout<<x<<"#\n";
      while (x < 6) {
        x++;
        cout << "0";
      }
      cout << a[i].first;
      x = cd(a[i].second);

      // cout<<x<<"#\n";
      while (x < 6) {
        x++;
        cout << "0";
      }
      cout << a[i].second << "\n";
    }
    if (t != 0)
      cout << "\n";
  }
  return 0;
}

Fixed submission:
// long time no ac
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define repe(i, I1, I2) for (i = I1; i < I2; i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define mod 1000000007

ll cd(ll n) {
  ll count = 0;
  while (n != 0) {
    n = n / 10;
    ++count;
  }
  return count;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k, t, c = 0, i, m, x, y;
  t = 1;
  // cin>>t;

  while (t--) {
    cin >> n >> m;
    vector<pair<ll, pair<ll, ll>>> h(m);
    pair<ll, ll> a[m];
    rep(i, m) {
      cin >> x >> y;
      a[i].first = x;
      a[i].second = y;
      h[i].first = x;
      h[i].second.first = y;
      h[i].second.second = i;
    }
    sort(h.begin(), h.end());
    ll prev = h[0].first;
    rep(i, m) {
      if (h[i].first == prev) {
        c++;
      } else {
        prev = h[i].first;
        c = 1;
      }
      a[h[i].second.second].second = c;
    }
    rep(i, m) {
      x = cd(a[i].first);
      // cout<<x<<"#\n";
      while (x < 6) {
        x++;
        cout << "0";
      }
      cout << a[i].first;
      x = cd(a[i].second);

      // cout<<x<<"#\n";
      while (x < 6) {
        x++;
        cout << "0";
      }
      cout << a[i].second << "\n";
    }
    if (t != 0)
      cout << "\n";
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, p[100000 + 1], y[100000 + 1];
  vector<int> num_list[100000];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &p[i], &y[i]);
    num_list[p[i] - 1].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(num_list[i].begin(), num_list[i].end());
  }
  for (int i = 0; i < m; i++) {
    printf("%06d", p[i]);
    auto tmp =
        1 + find(num_list[p[i] - 1].begin(), num_list[p[i] - 1].end(), y[i]) -
        num_list[p[i] - 1].begin();
    printf("%06ld\n", tmp);
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, p[100000 + 1], y[100000 + 1];
  vector<int> num_list[100000];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &p[i], &y[i]);
    num_list[p[i] - 1].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(num_list[i].begin(), num_list[i].end());
  }
  for (int i = 0; i < m; i++) {
    printf("%06d", p[i]);
    int tmp = 1 +
              lower_bound(num_list[p[i] - 1].begin(), num_list[p[i] - 1].end(),
                          y[i]) -
              num_list[p[i] - 1].begin();
    printf("%06d\n", tmp);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
#define rep(i, n) for (int i = 0; i < n; i++)
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  int p[m], y[m];
  scanf("%d%d", &n, &m);
  pair<ll, ll> Pair;
  vector<int> v[100001];
  rep(i, m) {
    scanf("%d%d", &p[i], &y[i]);
    v[p[i]].push_back(y[i]);
  }
  rep(i, n) { sort(v[i + 1].begin(), v[i + 1].end()); }
  rep(i, m) {
    printf("%012lld\n",
           ll(p[i]) * 1000000 +
               int(lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) -
                   v[p[i]].begin()) +
               1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
#define rep(i, n) for (int i = 0; i < n; i++)
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  int p[100000], y[100000];
  scanf("%d%d", &n, &m);
  pair<ll, ll> Pair;
  vector<int> v[100001];
  rep(i, m) {
    scanf("%d%d", &p[i], &y[i]);
    v[p[i]].push_back(y[i]);
  }
  rep(i, n) { sort(v[i + 1].begin(), v[i + 1].end()); }
  rep(i, m) {
    printf("%012lld\n",
           ll(p[i]) * 1000000 +
               int(lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) -
                   v[p[i]].begin()) +
               1);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

int main() {
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int> to(M + 5);
  std::vector<int> order(M + 5);
  int P, Y;
  std::vector<std::map<int, int>> mp(M + 5);
  for (int i = 0; i < M; i++) {
    scanf("%d", &P);
    scanf("%d", &Y);
    P--;
    to[i] = P;
    mp[P].insert(std::make_pair(Y, i));
  }
  for (int i = 0; i < N; i++) {
    // printf("i=%d\n", i);
    int counter = 0;
    for (auto entry : mp[i]) {
      order[entry.second] = counter;
      // printf("order[%d]=%d\n", entry.second, counter);
      counter++;
    }
    /*    for (int j=0; j<mp[i].size(); j++){
      order[mp[i][j].second]=j;
      }*/
  }
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", to[i] + 1, order[i] + 1);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

int main() {
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int> to(M + 5);
  std::vector<int> order(M + 5);
  int P, Y;
  std::vector<std::map<int, int>> mp(N + 5);
  for (int i = 0; i < M; i++) {
    scanf("%d", &P);
    scanf("%d", &Y);
    P--;
    to[i] = P;
    mp[P].insert(std::make_pair(Y, i));
  }
  for (int i = 0; i < N; i++) {
    // printf("i=%d\n", i);
    int counter = 0;
    for (auto entry : mp[i]) {
      order[entry.second] = counter;
      // printf("order[%d]=%d\n", entry.second, counter);
      counter++;
    }
    /*    for (int j=0; j<mp[i].size(); j++){
      order[mp[i][j].second]=j;
      }*/
  }
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", to[i] + 1, order[i] + 1);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct node {
  int x;
  int y;
  int z;
};
int cmp(node a, node b) {
  if (a.x == b.x) {
    return a.y < b.y;
  } else {
    return a.x < b.x;
  }
}
int main() {
  int n, m;
  node r[1000];
  bool vis[10000] = {0};
  int book[10000] = {0};
  node a[1000], b[1000];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i].x >> a[i].y;
    a[i].z = i;
    book[a[i].x]++;
  }
  sort(a, a + m, cmp);
  int num = 1;
  for (int i = 0; i < m; i++) {
    r[a[i].z].x = a[i].x;
    r[a[i].z].y = num;
    num++;
    if (a[i].x != a[i + 1].x)
      num = 1;
  }
  for (int i = 0; i < m; i++) {
    printf("%06d", r[i].x);
    printf("%06d\n", r[i].y);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int x;
  int y;
  int z;
};
int cmp(node a, node b) {
  if (a.x == b.x) {
    return a.y < b.y;
  } else {
    return a.x < b.x;
  }
}
int main() {
  int n, m;
  node r[100008];

  int book[100008] = {0};
  node a[100008], b[100008];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i].x >> a[i].y;
    a[i].z = i;
    book[a[i].x]++;
  }
  sort(a, a + m, cmp);
  int num = 1;
  for (int i = 0; i < m; i++) {
    r[a[i].z].x = a[i].x;
    r[a[i].z].y = num;
    num++;
    if (a[i].x != a[i + 1].x)
      num = 1;
  }
  for (int i = 0; i < m; i++) {
    printf("%06d", r[i].x);
    printf("%06d\n", r[i].y);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000

struct info {
  int p;
  int y;
  int x;
};

int main(void) {
  int n, m;
  cin >> n >> m;
  info py[NMAX];

  for (int i = 0; i < m; i++) {
    cin >> py[i].p >> py[i].y;
  }
  vector<int> mp[NMAX];
  for (int i = 0; i < m; i++) {
    mp[py[i].p].emplace_back(py[i].y);
  }
  for (int i = 0; i <= n; i++) {
    sort(mp[i].begin(), mp[i].end());
  }
  for (int i = 0; i < m; i++) {
    auto itr = find(mp[py[i].p].begin(), mp[py[i].p].end(), py[i].y);
    py[i].x = (int)(itr - mp[py[i].p].begin()) + 1;
    cout << setw(6) << setfill('0') << py[i].p;
    cout << setw(6) << setfill('0') << py[i].x << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000

struct info {
  int p;
  int y;
  int x;
};

int main(void) {
  int n, m;
  cin >> n >> m;
  info py[NMAX];

  for (int i = 0; i < m; i++) {
    cin >> py[i].p >> py[i].y;
  }
  vector<int> mp[NMAX];
  for (int i = 0; i < m; i++) {
    mp[py[i].p].emplace_back(py[i].y);
  }
  for (int i = 0; i <= n; i++) {
    sort(mp[i].begin(), mp[i].end());
  }
  for (int i = 0; i < m; i++) {
    auto itr = lower_bound(mp[py[i].p].begin(), mp[py[i].p].end(), py[i].y);
    py[i].x = (int)distance(mp[py[i].p].begin(), itr) + 1;
    cout << setw(6) << setfill('0') << py[i].p;
    cout << setw(6) << setfill('0') << py[i].x << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> City[N + 1];
  int P[M], Y[M];
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    City[p].push_back(y);
    P[i] = p, Y[i] = y;
  }

  for (int i = 0; i < N + 1; i++)
    sort(all(City[P[i]]));

  for (int i = 0; i < M; i++) {
    auto iter = upper_bound(all(City[P[i]]), Y[i]);
    cout << setfill('0') << right << setw(6) << P[i] << setfill('0') << right
         << setw(6) << iter - City[P[i]].begin() << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> City[N + 1];
  int P[M], Y[M];
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    City[p].push_back(y);
    P[i] = p, Y[i] = y;
  }

  for (int i = 0; i < N + 1; i++)
    sort(all(City[i]));

  for (int i = 0; i < M; i++) {
    auto iter = upper_bound(all(City[P[i]]), Y[i]);
    cout << setfill('0') << right << setw(6) << P[i] << setfill('0') << right
         << setw(6) << iter - City[P[i]].begin() << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repi(i, a, b) for (int i = a; i <= (b); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define pr(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int, int> P;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, M, y, p, ix;
int main() {
  cin >> N >> M;
  vector<pair<int, pair<int, int>>> city;
  vector<string> ans(M);
  rep(i, M) cin >> p >> y, city.pb(mp(p, mp(y, i + 1)));
  sort(ALL(city));
  int k = 1;
  rep(i, M) {
    int num = city[i].second.second;
    string ps = to_s(city[i].first);
    string s = "";
    rep(i, 6 - sz(ps)) s += "0";
    s += ps;
    rep(i, 6 - sz(to_s(k))) s += "0";
    s += to_s(k);
    ans[num] = s;

    if (i < M - 1 && city[i + 1].first == city[i].first)
      ++k;
    else
      k = 1;
  }
  rep1(i, M) pr(ans[i]);
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repi(i, a, b) for (int i = a; i <= (b); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define pr(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int, int> P;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, M, y, p, ix;
int main() {
  cin >> N >> M;
  vector<pair<int, pair<int, int>>> city;
  vector<string> ans(M + 1);
  rep(i, M) cin >> p >> y, city.pb(mp(p, mp(y, i + 1)));
  sort(ALL(city));
  int k = 1;
  rep(i, M) {
    int num = city[i].second.second;
    string ps = to_s(city[i].first);
    string s = "";
    rep(i, 6 - sz(ps)) s += "0";
    s += ps;
    rep(i, 6 - sz(to_s(k))) s += "0";
    s += to_s(k);
    ans[num] = s;

    if (i < M - 1 && city[i + 1].first == city[i].first)
      ++k;
    else
      k = 1;
  }
  rep1(i, M) pr(ans[i]);
}