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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p, y;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    p.push_back(make_pair(i, a));
    y.push_back(make_pair(b, i));
  }
  sort(y.begin(), y.end());
  map<int, int> mp;
  vector<int> ans(n, 0);
  rep(i, m) {
    int k = y[i].second;
    mp[p[k].second]++;
    ans[k] = mp[p[k].second];
  }

  rep(i, m) {
    cout << zero_pad(6) << p[i].second;
    cout << zero_pad(6) << ans[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p, y;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    p.push_back(make_pair(i, a));
    y.push_back(make_pair(b, i));
  }
  sort(y.begin(), y.end());
  map<int, int> mp;
  vector<int> ans(m, 0);
  rep(i, m) {
    int k = y[i].second;
    mp[p[k].second]++;
    ans[k] = mp[p[k].second];
  }

  rep(i, m) {
    cout << zero_pad(6) << p[i].second;
    cout << zero_pad(6) << ans[i] << endl;
  }
}
Problem p03221 (C++)

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

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

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, pair<int, int>>> da(m);
  vector<int> p(m), y(m);
    for
      rip(i, m) {
        scanf("%d%d", da[i].first, da[i].second.first);
        da[i].second.second = i;
      }
    sort(da.begin(), da.end());
    vector<pair<int, int>> ans(m);
    int co = 1;
    ans[da[0].second.second] = make_pair(da[0].first, 1);
    for (int i = 1; i < m; i++) {
      if (da[i].first == da[i - 1].first) {
        co++;
      } else {
        co = 1;
      }
      ans[da[i].second.second] = make_pair(da[i].first, co);
    }
    for
      rip(i, m) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

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

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, pair<int, int>>> da(m);
  vector<int> p(m), y(m);
    for
      rip(i, m) {
        scanf("%d%d", &da[i].first, &da[i].second.first);
        da[i].second.second = i;
      }
    sort(da.begin(), da.end());
    vector<pair<int, int>> ans(m);
    int co = 1;
    ans[da[0].second.second] = make_pair(da[0].first, 1);
    for (int i = 1; i < m; i++) {
      if (da[i].first == da[i - 1].first) {
        co++;
      } else {
        co = 1;
      }
      ans[da[i].second.second] = make_pair(da[i].first, co);
    }
    for
      rip(i, m) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

  for (int i = 1; i <= N; i++)
    sort(rank[i].begin(), rank[i].end());

  for (int i = 0; i < M; i++) {
    auto itr = lower_bound(rank[p[i]].begin(), rank[p[i]].end(), y[i]);
    int r = itr - rank[p[i]].begin() + 1;
    printf("%06d%06d\n", p[i], r);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

  for (int i = 1; i <= N; i++)
    sort(rank[i].begin(), rank[i].end());

  for (int i = 0; i < M; i++) {
    auto itr = lower_bound(rank[p[i]].begin(), rank[p[i]].end(), y[i]);
    int r = itr - rank[p[i]].begin() + 1;
    printf("%06d%06d\n", p[i], r);
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  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++) {
    int rank =
        distance(V[P[i]].begin(), find(V[P[i]].begin(), V[P[i]].end(), Y[i])) +
        1;
    printf("%06d%06d\n", P[i], rank);
  }
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  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++) {
    auto it1 = lower_bound(V[P[i]].begin(), V[P[i]].end(), Y[i]);
    int rank = it1 - V[P[i]].begin() + 1;
    printf("%06d%06d\n", P[i], rank);
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

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

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

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

  for (int i = 0; i < m; i++) {
    char num[13] = {};
    auto val = find(city[p[i]].begin(), city[p[i]].end(), y[i]);
    sprintf(num, "%06d%06d", p[i], distance(city[p[i]].begin(), val) + 1);
    cout << num << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

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

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

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

  for (int i = 0; i < m; i++) {
    char num[13] = {};
    // auto val = find(city[p[i]].begin(), city[p[i]].end(), y[i]);
    auto val = lower_bound(city[p[i]].begin(), city[p[i]].end(), y[i]);
    sprintf(num, "%06d%06d", p[i], distance(city[p[i]].begin(), val) + 1);
    cout << num << endl;
  }

  return 0;
}
Problem p03221 (C++)

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

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

  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < PY[P[i] - 1].size(); ++j) {
      if (Y[i] == PY[P[i] - 1][j]) {
        std::cout << std::setfill('0') << std::right << std::setw(6) << P[i];
        std::cout << std::setfill('0') << std::right << std::setw(6) << j + 1;
        std::cout << std::endl;
        break;
      }
    }
  }

  return 0;
}


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

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

  for (int i = 0; i < M; ++i) {
    int index =
        std::lower_bound(PY[P[i] - 1].begin(), PY[P[i] - 1].end(), Y[i]) -
        PY[P[i] - 1].begin();
    std::cout << std::setfill('0') << std::right << std::setw(6) << P[i];
    std::cout << std::setfill('0') << std::right << std::setw(6) << index + 1;
    std::cout << std::endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include <vector>

int main() {
  std::array<std::vector<uint64_t>, 100001> prefYears;
  std::array<int, 100000> p;
  std::array<uint64_t, 100000> y;

  int n, m;
  std::scanf("%d %d", &n, &m);

  for (std::size_t i = 0; i < m; ++i) {
    std::scanf("%d %lu", &(p[i]), &(y[i]));
    prefYears[p[i]].push_back(y[i]);
  }

  for (std::size_t i = 0; i < m; ++i) {
    std::sort(prefYears[p[i]].begin(), prefYears[p[i]].end());
  }

  for (std::size_t i = 0; i < m; ++i) {
    const std::vector<uint64_t> &years = prefYears[p[i]];

    std::vector<uint64_t>::const_iterator it =
        std::lower_bound(years.begin(), years.end(), y[i]);
    std::fprintf(stdout, "%06d%06lu\n", p[i],
                 (std::size_t)((it - years.begin())) + 1);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include <vector>

int main() {
  std::array<std::vector<uint64_t>, 100001> prefYears;
  std::array<int, 100000> p;
  std::array<uint64_t, 100000> y;

  int n, m;
  std::scanf("%d %d", &n, &m);

  for (std::size_t i = 0; i < m; ++i) {
    std::scanf("%d %lu", &(p[i]), &(y[i]));
    prefYears[p[i]].push_back(y[i]);
  }

  for (std::size_t i = 1; i <= n; ++i) {
    std::sort(prefYears[i].begin(), prefYears[i].end());
  }

  for (std::size_t i = 0; i < m; ++i) {
    const std::vector<uint64_t> &years = prefYears[p[i]];

    std::vector<uint64_t>::const_iterator it =
        std::lower_bound(years.begin(), years.end(), y[i]);
    std::fprintf(stdout, "%06d%06lu\n", p[i],
                 (std::size_t)((it - years.begin())) + 1);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// 変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

// for簡易表記(引数ミス防止)
#define FOR(LoopVariable, numberOFbegin, numberOFend)                          \
  for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend);     \
       (LoopVariable)++)
#define DEFOR(LoopVariable, numberOFbegin, numberOFend)                        \
  for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend);     \
       (LoopVariable)--)
#define REP(LoopVariable, numberOFend)                                         \
  for (int LoopVariable = 0; (LoopVariable) < (numberOFend); LoopVariable++)

int main() {

  int n, m;
  scanf("%d %d\n", &n, &m);
  array<int, 100001> ids, idt;
  vector<int> grid[100001];

  REP(i, m) {
    scanf("%d %d\n", &ids[i], &idt[i]);

    grid[ids[i]].push_back(idt[i]);
  }

  REP(i, n) { sort(grid[i + 1].begin(), grid[i + 1].end()); }

  REP(i, m) {

    printf("%06d%06ld\n", ids[i],
           distance(grid[ids[i]].begin(),
                    find(grid[ids[i]].begin(), grid[ids[i]].end(), idt[i])) +
               1);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// 変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

// for簡易表記(引数ミス防止)
#define FOR(LoopVariable, numberOFbegin, numberOFend)                          \
  for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend);     \
       (LoopVariable)++)
#define DEFOR(LoopVariable, numberOFbegin, numberOFend)                        \
  for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend);     \
       (LoopVariable)--)
#define REP(LoopVariable, numberOFend)                                         \
  for (int LoopVariable = 0; (LoopVariable) < (numberOFend); LoopVariable++)

int main() {

  int n, m;
  scanf("%d %d\n", &n, &m);
  array<int, 100001> ids, idt;
  vector<int> grid[100001];

  REP(i, m) {
    scanf("%d %d\n", &ids[i], &idt[i]);

    grid[ids[i]].push_back(idt[i]);
  }

  REP(i, n) { sort(grid[i + 1].begin(), grid[i + 1].end()); }

  REP(i, m) {

    printf("%06d%06d\n", ids[i],
           (int)(lower_bound(grid[ids[i]].begin(), grid[ids[i]].end(), idt[i]) -
                 grid[ids[i]].begin()) +
               1);
  }

  return 0;
}
Problem p03221 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> P(n + 1);
  vector<int> Y(n + 1);
  vector<vector<int>> YS(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> P[i] >> Y[i];
    YS[P[i]].push_back(Y[i]);
  }
  for (int i = 0; i <= n; i++) {
    if (!YS[i].empty()) {
      sort(YS[i].begin(), YS[i].end());
    }
  }
  for (int i = 0; i < m; i++) {
    int ord = lower_bound(YS[P[i]].begin(), YS[P[i]].end(), Y[i]) -
              YS[P[i]].begin() + 1;
    cout << setfill('0') << right << setw(6) << P[i];
    cout << setfill('0') << right << setw(6) << ord << endl;
  }

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> P(m);
  vector<int> Y(m);
  vector<vector<int>> YS(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> P[i] >> Y[i];
    YS[P[i]].push_back(Y[i]);
  }
  for (int i = 0; i <= n; i++) {
    if (!YS[i].empty()) {
      sort(YS[i].begin(), YS[i].end());
    }
  }
  for (int i = 0; i < m; i++) {
    int ord = lower_bound(YS[P[i]].begin(), YS[P[i]].end(), Y[i]) -
              YS[P[i]].begin() + 1;
    cout << setfill('0') << right << setw(6) << P[i];
    cout << setfill('0') << right << setw(6) << ord << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

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

  int P[100000], Y[100000];
  vector<int> v[100001];

  rep(i, m) {
    cin >> 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("%06d", P[i]);
    int r = 0;
    for (int j = 0; j < v[P[i]].size(); j++) {
      r++;
      if (v[P[i]][j] >= Y[i]) {
        break;
      }
    }
    printf("%06d", r);
    cout << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

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

  int P[100000], Y[100000];
  vector<int> v[100001];

  rep(i, m) {
    cin >> 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("%06d", P[i]);
    // int r=0;
    /*for(int j=0;j<v[P[i]].size();j++){
        r++;
        if(v[P[i]][j]>=Y[i]){
            break;
        }
    }*/
    int r =
        lower_bound(v[P[i]].begin(), v[P[i]].end(), Y[i]) - v[P[i]].begin() + 1;
    printf("%06d", r);
    cout << endl;
  }

  return 0;
}
Problem p03221 (C++)

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
#define put(n) cout << (n) << endl
#define rep(i, N) for (int(i) = 0; (i) < (N); ++(i))
#define rrep(i, N) for (int(i) = (N - 1); (i) >= (0); --(i))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<P>> city(N + 1);
  vector<int> ans1(N), ans2(N);

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    city[a].push_back({b, i});
  }

  rep(i, N + 1) {
    if (city[i].size() < 1)
      continue;
    sort(all(city[i]));
  }

  rep(i, N + 1) {
    rep(j, city[i].size()) {
      P c = city[i][j];
      ans1[c.second] = i;
      ans2[c.second] = j + 1;
    }
  }

  rep(i, M) {
    cout << setfill('0') << right << setw(6) << ans1[i];
    cout << setfill('0') << right << setw(6) << ans2[i] << endl;
  }
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
#define put(n) cout << (n) << endl
#define rep(i, N) for (int(i) = 0; (i) < (N); ++(i))
#define rrep(i, N) for (int(i) = (N - 1); (i) >= (0); --(i))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<P>> city(N + 1);
  vector<int> ans1(M), ans2(M);

  rep(i, M) {
    int a, b;
    cin >> a >> b;
    city[a].push_back({b, i});
  }

  rep(i, N + 1) {
    if (city[i].size() < 1)
      continue;
    sort(all(city[i]));
  }

  rep(i, N + 1) {
    rep(j, city[i].size()) {
      P c = city[i][j];
      ans1[c.second] = i;
      ans2[c.second] = j + 1;
    }
  }

  rep(i, M) {
    cout << setfill('0') << right << setw(6) << ans1[i];
    cout << setfill('0') << right << setw(6) << ans2[i] << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll INF = 1LL << 60;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<tuple<ll, ll, ll>> data(m);
  rep(i, n) {
    ll p;
    ll y;
    cin >> p;
    cin >> y;
    data[i] = make_tuple(y, p, i);
  }
  sort(data.begin(), data.end());
  vector<ll> cnt(n + 1);

  vector<pair<ll, ll>> id(m);
  for (ll i = 0; i < m; ++i) {
    ll y, p, idx;
    tie(y, p, idx) = data[i];
    ++cnt[p];
    id[idx] = make_pair(p, cnt[p]);
  }
  for (ll i = 0; i < m; ++i) {
    cout << setw(6) << setfill('0') << id[i].first;
    cout << setw(6) << setfill('0') << id[i].second << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll INF = 1LL << 60;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<tuple<ll, ll, ll>> data(m);
  rep(i, m) {
    ll p;
    ll y;
    cin >> p;
    cin >> y;
    data[i] = make_tuple(y, p, i);
  }
  sort(data.begin(), data.end());
  vector<ll> cnt(n + 1);

  vector<pair<ll, ll>> id(m);
  for (ll i = 0; i < m; ++i) {
    ll y, p, idx;
    tie(y, p, idx) = data[i];
    ++cnt[p];
    id[idx] = make_pair(p, cnt[p]);
  }
  for (ll i = 0; i < m; ++i) {
    cout << setw(6) << setfill('0') << id[i].first;
    cout << setw(6) << setfill('0') << id[i].second << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for (int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for (auto i : mp)
#define FOR(i, m, n) for (int i = m; i < n; i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
const int MAX_M = int(1e5);
ll P[MAX_M + 1], Y[MAX_M + 1];
vector<ll> nums[MAX_M + 1];

void solve() {
  REP(i, M) {
    auto at = find(nums[P[i]].begin(), nums[P[i]].end(), Y[i]);
    string sp = to_string(P[i]), sdiff = to_string(at - nums[P[i]].begin() + 1);
    if (sp.length() < 6)
      sp = string(6 - sp.length(), '0') + sp;
    if (sdiff.length() < 6)
      sdiff = string(6 - sdiff.length(), '0') + sdiff;
    string ans = sp + sdiff;
    printf("%s\n", ans.c_str());
  }
}

int main() {
  cin >> N >> M;
  REP(i, M) {
    scanf("%lli %lli", &P[i], &Y[i]);
    nums[P[i]].emplace_back(Y[i]);
  }
  REPONE(i, N) { sort(nums[i].begin(), nums[i].end()); }
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for (int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for (auto i : mp)
#define FOR(i, m, n) for (int i = m; i < n; i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
const int MAX_M = int(1e5);
ll P[MAX_M + 1], Y[MAX_M + 1];
vector<ll> nums[MAX_M + 1];

void solve() {
  REP(i, M) {
    auto at = lower_bound(nums[P[i]].begin(), nums[P[i]].end(), Y[i]);
    string sp = to_string(P[i]), sdiff = to_string(at - nums[P[i]].begin() + 1);
    if (sp.length() < 6)
      sp = string(6 - sp.length(), '0') + sp;
    if (sdiff.length() < 6)
      sdiff = string(6 - sdiff.length(), '0') + sdiff;
    string ans = sp + sdiff;
    printf("%s\n", ans.c_str());
  }
}

int main() {
  cin >> N >> M;
  REP(i, M) {
    scanf("%lli %lli", &P[i], &Y[i]);
    nums[P[i]].emplace_back(Y[i]);
  }
  REPONE(i, N) { sort(nums[i].begin(), nums[i].end()); }
  solve();
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
long long MOD = 1e9 + 7;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  vector<vector<int>> y_sort(n + 1);

  rep(i, m) {
    cin >> p[i] >> y[i];
    y_sort[p[i]].push_back(y[i]);
  }

  rep(i, n) { sort(y_sort[p[i + 1]].begin(), y_sort[p[i + 1]].end()); }

  for (int i = 0; i < m; i++) {
    printf("%012lld\n", ll(p[i]) * 1000000 +
                            int(lower_bound(all(y_sort[p[i]]), y[i]) -
                                y_sort[p[i]].begin()) +
                            1);
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
long long MOD = 1e9 + 7;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  vector<vector<int>> y_sort(n + 1);

  rep(i, m) {
    cin >> p[i] >> y[i];
    y_sort[p[i]].push_back(y[i]);
  }

  rep(i, n) { sort(y_sort[i + 1].begin(), y_sort[i + 1].end()); }

  for (int i = 0; i < m; i++) {
    printf("%012lld\n", ll(p[i]) * 1000000 +
                            int(lower_bound(all(y_sort[p[i]]), y[i]) -
                                y_sort[p[i]].begin()) +
                            1);
  }

  return 0;
}
Problem p03221 (C++)

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> pa;
  vector<vector<int>> c(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    pa.push_back({a, b});
    c[a].push_back(b);
  }
  for (int i = 0; i < c.size(); i++) {
    sort(c[i].begin(), c[i].end());
  }
  for (int i = 0; i < m; i++) {
    int x = pa[i].second;
    int index = distance(c[i].begin(), find(c[i].begin(), c[i].end(), x));
    cout << setw(6) << setfill('0') << pa[i].first + 1 << setw(6)
         << setfill('0') << index + 1 << endl;
  }
  return 0;
}

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> pa;
  vector<vector<int>> c(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    pa.push_back({a, b});
    c[a].push_back(b);
  }
  for (int i = 0; i < c.size(); i++) {
    sort(c[i].begin(), c[i].end());
  }
  for (int i = 0; i < m; i++) {
    int x = pa[i].second;
    int index = distance(c[pa[i].first].begin(),
                         find(c[pa[i].first].begin(), c[pa[i].first].end(), x));
    cout << setw(6) << setfill('0') << pa[i].first + 1 << setw(6)
         << setfill('0') << index + 1 << endl;
  }
  return 0;
}
Problem p03221 (C++)

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> pa;
  vector<vector<pair<int, int>>> c(n);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    p--;
    y--;
    pa.emplace_back(p, y);
    c[p].emplace_back(y, i);
  }
  for (int i = 0; i < m; i++) {
    sort(c[i].begin(), c[i].end());
    for (int j = 0; j < c[i].size(); j++) {
      pa[c[i][j].second].second = j;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << setw(6) << setfill('0') << pa[i].first + 1 << setw(6)
         << setfill('0') << pa[i].second + 1 << endl;
  }
  return 0;
}

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> pa;
  vector<vector<pair<int, int>>> c(n);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    p--;
    y--;
    pa.emplace_back(p, y);
    c[p].emplace_back(y, i);
  }
  for (int i = 0; i < n; i++) {
    sort(c[i].begin(), c[i].end());
    for (int j = 0; j < c[i].size(); j++) {
      pa[c[i][j].second].second = j;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << setw(6) << setfill('0') << pa[i].first + 1 << setw(6)
         << setfill('0') << pa[i].second + 1 << endl;
  }
  return 0;
}
Problem p03221 (C++)

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

int main() {
  // freopen("input.txt", "r", stdin);

  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> p(m), y(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &p[i], &y[i]);
  }

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

  for (int i = 0; i < n; ++i) {
    sort(a[i].begin(), a[i].end());
  }

  for (int i = 0; i < m; ++i) {
    printf("%06d", p[i]);
    auto itr = find(a[p[i] - 1].begin(), a[p[i] - 1].end(), y[i]);
    printf("%06d\n", distance(a[p[i] - 1].begin(), itr) + 1);
  }
  return 0;
}


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

int main() {
  // freopen("input.txt", "r", stdin);

  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> p(m), y(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &p[i], &y[i]);
  }

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

  for (int i = 0; i < n; ++i) {
    sort(a[i].begin(), a[i].end());
  }

  for (int i = 0; i < m; ++i) {
    auto itr = lower_bound(a[p[i] - 1].begin(), a[p[i] - 1].end(), y[i]);
    printf("%06d%06d\n", p[i], distance(a[p[i] - 1].begin(), itr) + 1);
  }
  return 0;
}
Problem p03221 (C++)

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

struct city {
  long long year;
  long long num;
  long long pref;
  long long order;
};

bool operator<(const struct city &a, const struct city &b) {
  return a.year > b.year;
}

priority_queue<struct city> que[10002];
vector<struct city> ps;

int main(void) {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long p, y;
    cin >> p >> y;

    struct city t;
    t.pref = p;
    t.num = i;
    t.year = y;
    que[p].push(t);
    ps.push_back(t);
  }

  for (long long i = 1; i <= n; i++) {
    long long cur = 1;
    while (!que[i].empty()) {
      struct city t = que[i].top();
      ps[t.num].order = cur;
      que[i].pop();
      cur++;
    }
  }

  for (long long i = 0; i < m; i++) {
    cout << std::setfill('0') << std::right << std::setw(6) << ps[i].pref;
    cout << std::setfill('0') << std::right << std::setw(6) << ps[i].order
         << endl;
  }

  return 0;
}

Fixed submission:
#include <iomanip>
#include <ios>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct city {
  long long year;
  long long num;
  long long pref;
  long long order;
};

bool operator<(const struct city &a, const struct city &b) {
  return a.year > b.year;
}

priority_queue<struct city> que[100002];
vector<struct city> ps;

int main(void) {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long p, y;
    cin >> p >> y;

    struct city t;
    t.pref = p;
    t.num = i;
    t.year = y;
    que[p].push(t);
    ps.push_back(t);
  }

  for (long long i = 1; i <= n; i++) {
    long long cur = 1;
    while (!que[i].empty()) {
      struct city t = que[i].top();
      ps[t.num].order = cur;
      que[i].pop();
      cur++;
    }
  }

  for (long long i = 0; i < m; i++) {
    cout << std::setfill('0') << std::right << std::setw(6) << ps[i].pref;
    cout << std::setfill('0') << std::right << std::setw(6) << ps[i].order
         << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int p[100005];
int y[100005];
vector<int> order[100005];

int main() {
  int n, m;
  cin >> n >> m;
  REP(i, m) {
    cin >> p[i];
    cin >> y[i];
    order[p[i] - 1].push_back(y[i]);
  }
  REP(i, n) sort(ALL(order[i]));
  REP(i, m) {
    printf("%06d", p[i]);
    printf("%06d",
           find(ALL(order[p[i] - 1]), y[i]) - order[p[i] - 1].begin() + 1);
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int p[100005];
int y[100005];
vector<int> order[100005];

int main() {
  int n, m;
  cin >> n >> m;
  REP(i, m) {
    cin >> p[i];
    cin >> y[i];
    order[p[i] - 1].push_back(y[i]);
  }
  REP(i, n) sort(ALL(order[i]));
  REP(i, m) {
    printf("%06d", p[i]);
    printf("%06d", lower_bound(ALL(order[p[i] - 1]), y[i]) -
                       order[p[i] - 1].begin() + 1);
    printf("\n");
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, list<pair<int, int>>> town;
  town.clear();
  int ken = 0, val = 0;
  string ans[10000] = {""};
  for (int i = 0; i < m; ++i) {
    cin >> ken >> val;
    town[ken].push_back(pair<int, int>(val, i));
  }
  for (int i = 1; i <= n; ++i) {
    town[i].sort();
    list<pair<int, int>>::iterator it = town[i].begin();
    int cnt = 1;
    while (it != town[i].end()) {
      stringstream strStream;
      strStream << setfill('0') << right << setw(6) << i;
      strStream << setfill('0') << right << setw(6) << cnt;
      ans[(*it).second] = strStream.str();
      ++it;
      ++cnt;
    }
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}


Fixed submission:
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, list<pair<int, int>>> town;
  town.clear();
  int ken = 0, val = 0;
  string ans[100000] = {""};
  for (int i = 0; i < m; ++i) {
    cin >> ken >> val;
    town[ken].push_back(pair<int, int>(val, i));
  }
  for (int i = 1; i <= n; ++i) {
    town[i].sort();
    list<pair<int, int>>::iterator it = town[i].begin();
    int cnt = 1;
    while (it != town[i].end()) {
      stringstream strStream;
      strStream << setfill('0') << right << setw(6) << i;
      strStream << setfill('0') << right << setw(6) << cnt;
      ans[(*it).second] = strStream.str();
      ++it;
      ++cnt;
    }
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}
Problem p03221 (Python)

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

input = sys.stdin.readline
N, M = list(map(int, input().split()))

PY = []
for _ in range(M):
    PY.append(list(map(int, input().split())))

sorted_PY = deepcopy(PY)
sorted_PY.sort(key=lambda x: x[1])

p_count_dict = defaultdict(lambda: 0)
y_dict = {}

for py in sorted_PY:
    p_count_dict[py[0]] += 1
    y_dict[py[1]] = p_count_dict[py[0]]

for py in PY:
    print(f"{py[0]:0>6}{y_dict[py[1]]:0>6}")


Fixed submission:
import sys
from collections import defaultdict
from copy import deepcopy

input = sys.stdin.readline
N, M = list(map(int, input().split()))

PY = []
for _ in range(M):
    PY.append(list(map(int, input().split())))

sorted_PY = deepcopy(PY)
sorted_PY.sort(key=lambda x: x[1])

p_count_dict = defaultdict(lambda: 0)
y_dict = {}

for py in sorted_PY:
    p_count_dict[py[0]] += 1
    y_dict[py[1]] = p_count_dict[py[0]]

for py in PY:
    # print(f'{py[0]:0>6}{y_dict[py[1]]:0>6}')
    print("{}{}".format(str(py[0]).zfill(6), str(y_dict[py[1]]).zfill(6)))
Problem p03221 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

res = [""] * M
ctr = [0] * (M + 1)
for i, (p, y) in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ctr[p] += 1
    res[i] = "{:0>6}{:0>6}".format(p, ctr[p])

print(*res, sep="\n")


Fixed submission:
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

res = [""] * M
ctr = [0] * (N + 1)
for i, (p, y) in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ctr[p] += 1
    res[i] = "{:0>6}{:0>6}".format(p, ctr[p])

print(*res, sep="\n")
Problem p03221 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
timeline = []
for i in range(M):
    P, Y = map(int, input().split())
    timeline.append((Y, P, i))
timeline.sort()
count = [0] * (N + 1)
number = [(0, 0)] * M
for y, p, i in timeline:
    count[p] += 1
    number[i] = (p, count[p])
for i in range(M):
    print(f"{number[i][0]:06}{number[i][1]:06}")


Fixed submission:
N, M = map(int, input().split())
timeline = []
for i in range(M):
    P, Y = map(int, input().split())
    timeline.append((Y, P, i))
timeline.sort()
count = [0] * (N + 1)
number = [(0, 0)] * M
for y, p, i in timeline:
    count[p] += 1
    number[i] = (p, count[p])
for i in range(M):
    print("{:06}{:06}".format(number[i][0], number[i][1]))
Problem p03221 (C++)

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

struct City {
  int prefecture;
  int year;
  int x;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<City> city(M);
  map<int, map<int, int>> years;
  for (int i = 1; i <= M; i++) {
    int Pi, Yi;
    cin >> Pi >> Yi;
    city[i].prefecture = Pi, city[i].year = Yi;
    years[Pi][Yi] = i;
  }

  for (int Pi = 1; Pi <= N; Pi++) {
    int x = 1;
    for (auto year_i : years[Pi])
      city[year_i.second].x = x++;
  }

  for (int i = 1; i <= M; i++) {
    cout << setfill('0');
    cout << setw(6) << city[i].prefecture;
    cout << setw(6) << city[i].x << endl;
  }
}

Fixed submission:
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

struct City {
  int prefecture;
  int year;
  int x;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<City> city(M + 1);
  map<int, map<int, int>> years;
  for (int i = 1; i <= M; i++) {
    int Pi, Yi;
    cin >> Pi >> Yi;
    city[i].prefecture = Pi, city[i].year = Yi;
    years[Pi][Yi] = i;
  }

  for (int Pi = 1; Pi <= N; Pi++) {
    int x = 1;
    for (auto year_i : years[Pi])
      city[year_i.second].x = x++;
  }

  for (int i = 1; i <= M; i++) {
    cout << setfill('0');
    cout << setw(6) << city[i].prefecture;
    cout << setw(6) << city[i].x << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
#define mt make_tuple
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> a;
  vector<int> cnt(m, 0);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    a.pb(mt(p, y, i));
    cnt[p - 1]++;
  }
  sort(a.begin(), a.end());
  vector<pair<string, string>> ans(m);
  int k = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      string str = "000000";
      ans[get<2>(a[k])].first =
          str.substr(0, 6 - to_string(i + 1).length()) + to_string(i + 1);
      ans[get<2>(a[k])].second =
          str.substr(0, 6 - to_string(j + 1).length()) + to_string(j + 1);
      k++;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i].first << ans[i].second << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
#define mt make_tuple
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> a;
  vector<int> cnt(n, 0);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    a.pb(mt(p, y, i));
    cnt[p - 1]++;
  }
  sort(a.begin(), a.end());
  vector<pair<string, string>> ans(m);
  int k = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      string str = "000000";
      ans[get<2>(a[k])].first =
          str.substr(0, 6 - to_string(i + 1).length()) + to_string(i + 1);
      ans[get<2>(a[k])].second =
          str.substr(0, 6 - to_string(j + 1).length()) + to_string(j + 1);
      k++;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i].first << ans[i].second << endl;
  }
}
Problem p03221 (C++)

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<PP> C(M);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    C[i] = PP(P(p, y), i);
  }
  sort(C.begin(), C.end());

  vector<P> res(N);
  int pre = 0, cnt = 0;
  for (int i = 0; i < M; i++) {
    int p = C[i].first.first;
    if (p == pre) {
      cnt++;
    } else {
      cnt = 1;
    }
    pre = p;
    res[C[i].second] = P(p, cnt);
  }

  for (int i = 0; i < M; i++) {
    printf("%.6d%.6d\n", res[i].first, res[i].second);
  }
  return 0;
}

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<PP> C(M);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    C[i] = PP(P(p, y), i);
  }
  sort(C.begin(), C.end());

  vector<P> res(M);
  int pre = 0, cnt = 0;
  for (int i = 0; i < M; i++) {
    int p = C[i].first.first;
    if (p == pre) {
      cnt++;
    } else {
      cnt = 1;
    }
    pre = p;
    res[C[i].second] = P(p, cnt);
  }

  for (int i = 0; i < M; i++) {
    printf("%.6d%.6d\n", res[i].first, res[i].second);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  vector<pair<int, int>> o(m);
  repi(i, m, 0) {
    int p, y;
    cin >> p >> y;
    v[p - 1].push_back(y);
    o[i].first = p;
    o[i].second = y;
  }
  repi(i, n, 0) { sort(v[i].begin(), v[i].end()); }
  repi(i, m, 0) {
    int p = o[i].first, y = o[i].second;
    int cnt = 0;
    repi(j, v[p - 1].size(), 0) {
      cnt++;
      if (v[p - 1][j] == y) {
        string pid = "000000", yid = "000000";
        pid += to_string(p);
        yid += to_string(cnt);
        cout << pid.substr(pid.size() - 6) + yid.substr(yid.size() - 6) << endl;
        break;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  vector<pair<int, int>> o(m);
  repi(i, m, 0) {
    int p, y;
    cin >> p >> y;
    v[p - 1].push_back(y);
    o[i].first = p;
    o[i].second = y;
  }
  repi(i, n, 0) { sort(v[i].begin(), v[i].end()); }
  repi(i, m, 0) {
    int p = o[i].first, y = o[i].second;
    int cnt = 0;
    auto itr = lower_bound(v[p - 1].begin(), v[p - 1].end(), y);
    string pid = "000000", yid = "000000";
    pid += to_string(p);
    yid += to_string(distance(v[p - 1].begin(), itr) + 1);
    cout << pid.substr(pid.size() - 6) + yid.substr(yid.size() - 6) << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> p(m), y(m);
  rep(i, m) cin >> p[i] >> y[i];

  map<pair<ll, ll>, ll> mp;
  for (int i = 0; i < m; i++) {
    mp[make_pair(p[i], y[i])];
  }

  vector<ll> cnt(m, 0);
  for (auto x : mp) {
    cnt[x.first.first - 1]++;
    mp[x.first] = cnt[x.first.first - 1];
    // cout << x.first.first << " " << x.first.second << " " << x.second <<
    // endl;
  }

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << p[i];
    cout << setfill('0') << right << setw(6) << mp[make_pair(p[i], y[i])]
         << endl;
  }

  // for(auto x:mp) cout << x.first.first << " " << x.first.second << " " <<
  // x.second << endl; for(auto x:cnt) cout << x << " "; cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> p(m), y(m);
  rep(i, m) cin >> p[i] >> y[i];

  map<pair<ll, ll>, ll> mp;
  for (int i = 0; i < m; i++) {
    mp[make_pair(p[i], y[i])];
  }

  vector<ll> cnt(n, 0);
  for (auto x : mp) {
    cnt[x.first.first - 1]++;
    mp[x.first] = cnt[x.first.first - 1];
    // cout << x.first.first << " " << x.first.second << " " << x.second <<
    // endl;
  }

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << p[i];
    cout << setfill('0') << right << setw(6) << mp[make_pair(p[i], y[i])]
         << endl;
  }

  // for(auto x:mp) cout << x.first.first << " " << x.first.second << " " <<
  // x.second << endl; for(auto x:cnt) cout << x << " "; cout << endl;
}