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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P1> a(M);
  rep(i, M) cin >> a[i].fi >> a[i].sc.fi;
  rep(i, M) a[i].sc.sc = i;
  SORT(a);

  vector<int> num(M);
  int cnt = 1;
  num[0] = cnt;
  rep(i, M) {
    if (a[i].fi == a[i + 1].fi)
      num[i + 1] = ++cnt;
    else {
      cnt = 1;
      num[i + 1] = cnt;
    }
  }

  vector<P1> b(M);
  rep(i, M) {
    b[i].fi = a[i].sc.sc;
    b[i].sc.fi = a[i].fi;
    b[i].sc.sc = num[i];
  }
  SORT(b);

  rep(i, M) {
    printf("%06d", b[i].sc.fi);
    printf("%06d", b[i].sc.sc);
    cout << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P1> a(M);
  rep(i, M) cin >> a[i].fi >> a[i].sc.fi;
  rep(i, M) a[i].sc.sc = i;
  SORT(a);

  vector<int> num(M);
  int cnt = 1;
  num[0] = cnt;
  rep(i, M - 1) {
    if (a[i].fi == a[i + 1].fi)
      num[i + 1] = ++cnt;
    else {
      cnt = 1;
      num[i + 1] = cnt;
    }
  }

  vector<P1> b(M);
  rep(i, M) {
    b[i].fi = a[i].sc.sc;
    b[i].sc.fi = a[i].fi;
    b[i].sc.sc = num[i];
  }
  SORT(b);

  rep(i, M) {
    printf("%06d", b[i].sc.fi);
    printf("%06d", b[i].sc.sc);
    cout << endl;
  }
}
Problem p03221 (C++)

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

using namespace std;

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

  for (auto &pn : PN)
    sort(pn.begin(), pn.end());
  for (int i = 0; i < M; i++) {
    int index;
    for (int j = 0; j < PN[P[i] - 1].size(); j++) {
      if (PN[P[i] - 1][j] == Y[i]) {
        index = j;
        break;
      }
    }
    printf("%06d%06d\n", P[i], index + 1);
  }

  return 0;
}

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

using namespace std;

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

  for (auto &pn : PN)
    sort(pn.begin(), pn.end());
  for (int i = 0; i < M; i++) {
    auto itr = lower_bound(PN[P[i] - 1].begin(), PN[P[i] - 1].end(), Y[i]);

    printf("%06d%06d\n", P[i], 1 + distance(PN[P[i] - 1].begin(), itr));
  }

  return 0;
}
Problem p03221 (C++)

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

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> p(m), y(m);
  std::vector<std::vector<int>> vec(n + 1);
  for (int i = 0; i < m; i++) {
    std::cin >> p[i] >> y[i];
    vec[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; i++) {
    std::sort(vec[i].begin(), vec[i].end());
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < vec[p[i]].size(); j++) {
      if (vec[p[i]][j] == y[i]) {
        std::cout << std::setfill('0') << std::right << std::setw(6) << p[i]
                  << std::setfill('0') << std::right << std::setw(6) << j + 1
                  << std::endl;
      }
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> p(m), y(m);
  std::vector<std::vector<int>> vec(n + 1);
  for (int i = 0; i < m; i++) {
    std::cin >> p[i] >> y[i];
    vec[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; i++) {
    std::sort(vec[i].begin(), vec[i].end());
  }

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

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int gcd(int x, int y) {
  x = std::abs(x);
  y = std::abs(y);
  int a = std::max(x, y), b = std::min(x, y);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

long long lcm(int x, int y) { return (long long)x * y / gcd(x, y); }

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  std::vector<std::pair<int, int>> cities(M), sorted(M);
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &(cities[i].first), &(cities[i].second));
    sorted[i] = cities[i];
  }
  sort(sorted.begin(), sorted.end());
  int c = 0, n = 0;
  std::vector<std::pair<int, int>> ids(M);
  for (int i = 0; i < M; ++i) {
    if (sorted[i].first != c) {
      c = sorted[i].first;
      n = 0;
    }
    ids[i].first = c;
    ids[i].second = ++n;
  }
  for (int i = 0; i < M; ++i) {
    std::vector<std::pair<int, int>>::iterator it =
        std::lower_bound(sorted.begin(), sorted.end(), cities[i]);
    int idx = it - cities.begin();
    printf("%06d%06d\n", ids[idx].first, ids[idx].second);
  }

  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int gcd(int x, int y) {
  x = std::abs(x);
  y = std::abs(y);
  int a = std::max(x, y), b = std::min(x, y);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

long long lcm(int x, int y) { return (long long)x * y / gcd(x, y); }

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  std::vector<std::pair<int, int>> cities(M), sorted(M);
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &(cities[i].first), &(cities[i].second));
    sorted[i] = cities[i];
  }
  sort(sorted.begin(), sorted.end());
  int c = 0, n = 0;
  std::vector<std::pair<int, int>> ids(M);
  for (int i = 0; i < M; ++i) {
    if (sorted[i].first != c) {
      c = sorted[i].first;
      n = 0;
    }
    ids[i].first = c;
    ids[i].second = ++n;
  }
  for (int i = 0; i < M; ++i) {
    std::vector<std::pair<int, int>>::iterator it =
        std::lower_bound(sorted.begin(), sorted.end(), cities[i]);
    int idx = it - sorted.begin();
    printf("%06d%06d\n", ids[idx].first, ids[idx].second);
  }

  return 0;
}
Problem p03221 (C++)

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

int main() {
  const int M = 1000;
  int n, m, p[M], y[M];
  vector<int> num[M];

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    num[p[i] - 1].push_back(y[i]);
  }
  for (int i = 0; i < n; i++)
    sort(num[i].begin(), num[i].end());
  for (int i = 0; i < m; i++) {
    printf("%06d", p[i]);
    auto tmp = lower_bound(num[p[i] - 1].begin(), num[p[i] - 1].end(), y[i]) -
               num[p[i] - 1].begin() + 1;
    printf("%06d\n", tmp);
  }
}

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

int main() {
  const int M = 100000;
  int n, m, p[M], y[M];
  vector<int> num[M];

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    num[p[i] - 1].push_back(y[i]);
  }
  for (int i = 0; i < n; i++)
    sort(num[i].begin(), num[i].end());
  for (int i = 0; i < m; i++) {
    printf("%06d", p[i]);
    auto tmp = lower_bound(num[p[i] - 1].begin(), num[p[i] - 1].end(), y[i]) -
               num[p[i] - 1].begin() + 1;
    printf("%06d\n", tmp);
  }
}
Problem p03221 (C++)

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  auto ys = vector<pair<int, pair<int, int>>>(m);
  auto ps = vector<int>(n);
  for (int i = 0; i < m; ++i) {
    int p, y;
    cin >> p >> y;
    ys[i] = make_pair(y, make_pair(i, p));
    ps[i] = p;
  }
  sort(ys.begin(), ys.end());
  auto xs = vector<int>(n, 0);
  auto rs = vector<int>(m, 0);
  for (int i = 0; i < m; ++i) {
    ++xs[ys[i].second.second - 1];
    rs[ys[i].second.first] = xs[ys[i].second.second - 1];
  }
  for (int i = 0; i < m; ++i) {
    printf("%06d%06d\n", ps[i], rs[i]);
  }
  return 0;
}


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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  auto ys = vector<pair<int, pair<int, int>>>(m);
  auto ps = vector<int>(m);
  for (int i = 0; i < m; ++i) {
    int p, y;
    cin >> p >> y;
    ys[i] = make_pair(y, make_pair(i, p));
    ps[i] = p;
  }
  sort(ys.begin(), ys.end());
  auto xs = vector<int>(n, 0);
  auto rs = vector<int>(m, 0);
  for (int i = 0; i < m; ++i) {
    ++xs[ys[i].second.second - 1];
    rs[ys[i].second.first] = xs[ys[i].second.second - 1];
  }
  for (int i = 0; i < m; ++i) {
    printf("%06d%06d\n", ps[i], rs[i]);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> id(N + 1);
  vector<vector<ll>> tmp(N + 1);
  REP(i, M) {
    ll p, y;
    cin >> p >> y;
    id[i] = make_pair(p, y);
  }
  REP(i, M) { tmp[id[i].first].push_back(id[i].second); }
  REP(i, N + 1) { sort(all(tmp[i])); }
  for (ll i = 0; i < M; ++i) {
    int ans = lower_bound(all(tmp[id[i].first]), id[i].second) -
              tmp[id[i].first].begin();
    cout << setw(6) << setfill('0') << id[i].first << setw(6) << setfill('0')
         << (ans + 1) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> id(M);
  vector<vector<ll>> tmp(N + 1);
  REP(i, M) {
    ll p, y;
    cin >> p >> y;
    id[i] = make_pair(p, y);
  }
  REP(i, M) { tmp[id[i].first].push_back(id[i].second); }
  REP(i, N + 1) { sort(all(tmp[i])); }
  for (ll i = 0; i < M; ++i) {
    int ans = lower_bound(all(tmp[id[i].first]), id[i].second) -
              tmp[id[i].first].begin();
    cout << setw(6) << setfill('0') << id[i].first << setw(6) << setfill('0')
         << (ans + 1) << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9 + 7
#define LINF (long long)4e18

void dfs() {}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  rep(i, M) cin >> P[i] >> Y[i];
  vector<vector<int>> PY(N + 100);
  rep(i, M) { PY[P[i]].push_back(Y[i]); }
  for (auto i : P) {
    sort(PY[i].begin(), PY[i].end());
  }
  rep(i, M) {
    printf("%012lld\n",
           (long long)(P[i]) * 1000000 +
               lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]) -
               PY[P[i]].begin() + 1);
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9 + 7
#define LINF (long long)4e18

void dfs() {}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  rep(i, M) cin >> P[i] >> Y[i];
  vector<vector<int>> PY(N + 100);
  rep(i, M) { PY[P[i]].push_back(Y[i]); }
  repr(i, 1, N + 1) { sort(PY[i].begin(), PY[i].end()); }
  rep(i, M) {
    printf("%012lld\n",
           (long long)(P[i]) * 1000000 +
               lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]) -
               PY[P[i]].begin() + 1);
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
const int INF = 2000000000;

int n, m;

int main() {
  cin >> n >> m;
  vector<vector<int>> v(n);
  int ans_1[100000];
  int year[100000];
  rep(i, m) {
    cin >> ans_1[i];
    int tmp;
    cin >> year[i];
    v[ans_1[i] - 1].push_back(year[i]);
  }
  rep(i, n) sort(all(v[i]));
  ;
  rep(i, m) {
    printf("%06d", ans_1[i]);
    const int result =
        distance(v[ans_1[i] - 1].begin(), find(all(v[ans_1[i] - 1]), year[i]));
    printf("%06d\n", result + 1);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
const int INF = 2000000000;

int n, m;

int main() {
  cin >> n >> m;
  vector<vector<int>> v(n);
  int ans_1[100000];
  int year[100000];
  rep(i, m) {
    cin >> ans_1[i];
    int tmp;
    cin >> year[i];
    v[ans_1[i] - 1].push_back(year[i]);
  }
  rep(i, n) sort(all(v[i]));
  ;
  rep(i, m) {
    printf("%06d", ans_1[i]);
    int itr = distance(v[ans_1[i] - 1].begin(),
                       lower_bound(all(v[ans_1[i] - 1]), year[i]));
    printf("%06d\n", itr + 1);
  }
}
Problem p03221 (C++)

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

int length(int n) {
  int i = 1;
  while (n != 0) {
    n = n / 10;
    ++i;
  }
  return i;
}

int main() {
  int n, m, i, j, k = 1;
  cin >> n >> m;
  vector<int> p(m), y(m), ans1(n, 1), ans2(n, 0);
  map<int, pair<int, int>> mp;
  for (i = 0; i < m; ++i) {
    cin >> p[i] >> y[i];
    mp[y[i]] = make_pair(p[i], i);
  }
  for (auto q : mp) {
    ans2[q.second.second] = ans1[q.second.first - 1];
    ++ans1[q.second.first - 1];
    ++i;
  }
  for (i = 0; i < m; ++i) {
    for (j = 0; j <= 6 - length(p[i]); ++j) {
      cout << 0;
    }
    cout << p[i];
    for (j = 0; j <= 6 - length(ans2[i]); ++j) {
      cout << 0;
    }
    cout << ans2[i];
    cout << "\n";
  }
  return 0;
}

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

int length(int n) {
  int i = 1;
  while (n != 0) {
    n = n / 10;
    ++i;
  }
  return i;
}

int main() {
  int n, m, i, j, k = 1;
  cin >> n >> m;
  vector<int> p(m), y(m), ans1(n, 1), ans2(m, 0);
  map<int, pair<int, int>> mp;
  for (i = 0; i < m; ++i) {
    cin >> p[i] >> y[i];
    mp[y[i]] = make_pair(p[i], i);
  }
  for (auto q : mp) {
    ans2[q.second.second] = ans1[q.second.first - 1];
    ++ans1[q.second.first - 1];
    ++i;
  }
  for (i = 0; i < m; ++i) {
    for (j = 0; j <= 6 - length(p[i]); ++j) {
      cout << 0;
    }
    cout << p[i];
    for (j = 0; j <= 6 - length(ans2[i]); ++j) {
      cout << 0;
    }
    cout << ans2[i];
    cout << "\n";
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
using namespace std;

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

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

  int p[m], y[m];
  vector<int> yd[m];
  REP(i, m) {
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }

  REP(i, n) { SORT(yd[i + 1]); }
  REP(i, m) {
    cout << setfill('0') << setw(6) << p[i];
    cout << setfill('0') << setw(6)
         << lower_bound(ALL(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1 << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
using namespace std;

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

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

  int p[100000], y[100000];
  vector<int> yd[100001];
  REP(i, m) {
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }

  REP(i, n) { SORT(yd[i + 1]); }
  REP(i, m) {
    cout << setfill('0') << setw(6) << p[i];
    cout << setfill('0') << setw(6)
         << lower_bound(ALL(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1 << endl;
  }

  return 0;
}
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 repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pii>> a(n, vector<pii>());
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    a[p].push_back(mp(y, i));
  }

  vector<pii> b(m);
  rep(i, n) {
    sort(all(a[i]));
    rep(j, a[i].size()) {
      int y, num;
      tie(y, num) = a[i][j];
      b[num] = mp(i, j);
    }
  }

  rep(i, m) {
    int p, yy;
    tie(p, yy) = b[i];
    printf("%06d%06d\n", p + 1, yy + 1);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pii>> a(n, vector<pii>());
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    p--;
    a[p].push_back(mp(y, i));
  }

  vector<pii> b(m);
  rep(i, n) {
    sort(all(a[i]));
    rep(j, a[i].size()) {
      int y, num;
      tie(y, num) = a[i][j];
      b[num] = mp(i, j);
    }
  }

  rep(i, m) {
    int p, yy;
    tie(p, yy) = b[i];
    printf("%06d%06d\n", p + 1, yy + 1);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mxsz = 1e5;
int n, m;
map<pii, int> mp;
vi pi[mxsz];
pii req[mxsz];

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

  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> req[i].fi >> req[i].se;
    pi[req[i].fi].pb(req[i].se);
  }
  for (int i = 1; i <= n; i++) {
    if (!pi[i].empty()) {
      sort(pi[i].begin(), pi[i].end());
      for (int j = 1; j <= pi[i].size(); j++) {
        pii tmp = {i, pi[i][j - 1]};
        mp[tmp] = j;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    pii tmp = {req[i].fi, req[i].se};
    printf("%06d%06d\n", req[i].fi, mp[tmp]);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mxsz = 1e5 + 5;
int n, m;
map<pii, int> mp;
vi pi[mxsz];
pii req[mxsz];

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

  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> req[i].fi >> req[i].se;
    pi[req[i].fi].pb(req[i].se);
  }
  for (int i = 1; i <= n; i++) {
    if (!pi[i].empty()) {
      sort(pi[i].begin(), pi[i].end());
      for (int j = 1; j <= pi[i].size(); j++) {
        pii tmp = {i, pi[i][j - 1]};
        mp[tmp] = j;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    pii tmp = {req[i].fi, req[i].se};
    printf("%06d%06d\n", req[i].fi, mp[tmp]);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> A;
#define int long long
int N, M;
pair<int, int> K[100001];
signed main() {
  cin >> N >> M;
  vector<A> vec[100001];
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    vec[P].push_back(A(Y, i));
  }
  for (int i = 1; i <= N; i++) {
    sort(vec[i].begin(), vec[i].end());
    K[vec[i][i].second].first = vec[i][i].first;
    K[vec[i][i].second].second = vec[i][i].second;
  }
  for (int i = 0; i < M; i++) {
    printf("%06d"
           "%06d\n",
           K[i].first, K[i].second);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> A;
#define int long long
int N, M;
pair<int, int> K[100001];
signed main() {
  cin >> N >> M;
  vector<A> vec[100001];
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    vec[P].push_back(A(Y, i));
  }
  for (int i = 1; i <= N; i++) {
    sort(vec[i].begin(), vec[i].end());
    for (int j = 0; j < vec[i].size(); j++) {
      K[vec[i][j].second].first = i;
      K[vec[i][j].second].second = j + 1;
    }
  }
  for (int i = 0; i < M; i++) {
    printf("%06d"
           "%06d\n",
           K[i].first, K[i].second);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  ll p[m], y[m];
  vector<ll> py[m];
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i];

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

  /*	for(int i=0;i<m;i++){
                  printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
          }*/
  //	for(int i=0;i<m;i++)num[y[i]]=i;
  // sort(y,y+m);
  /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
       std::cout << i << std::endl;
    }*/
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  ll p[m], y[m];
  vector<ll> py[100001];
  for (int i = 0; i < m; i++)
    cin >> p[i] >> y[i];

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

  /*	for(int i=0;i<m;i++){
                  printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
          }*/
  //	for(int i=0;i<m;i++)num[y[i]]=i;
  // sort(y,y+m);
  /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
       std::cout << i << std::endl;
    }*/
}
Problem p03221 (C++)

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

using namespace std;

int main() {

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

  vector<map<int, int>> py(m + 1);
  vector<vector<int>> numm(m + 1, vector<int>(2));
  int tmp1, tmp2;
  for (int i = 1; i <= m; i++) {
    cin >> tmp1 >> tmp2;
    py[tmp1][tmp2] = 0;
    numm[i][0] = tmp1;
    numm[i][1] = tmp2;
  }

  for (int i = 1; i <= n; i++) {
    int counter = 1;
    for (auto itr = py[i].begin(); itr != py[i].end(); itr++) {
      itr->second = counter;
      counter++;
    }
  }

  for (int i = 1; i <= m; i++) {
    cout << std::setfill('0') << std::right << std::setw(6) << numm[i][0]
         << std::setfill('0') << std::right << std::setw(6)
         << py[numm[i][0]][numm[i][1]] << endl;
  }
  return 0;
}

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

using namespace std;

int main() {

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

  vector<map<int, int>> py(n + 1);
  vector<vector<int>> numm(m + 1, vector<int>(2));
  int tmp1, tmp2;
  for (int i = 1; i <= m; i++) {
    cin >> tmp1 >> tmp2;
    py[tmp1][tmp2] = 0;
    numm[i][0] = tmp1;
    numm[i][1] = tmp2;
  }

  for (int i = 1; i <= n; i++) {
    int counter = 1;
    for (auto itr = py[i].begin(); itr != py[i].end(); itr++) {
      itr->second = counter;
      counter++;
    }
  }

  for (int i = 1; i <= m; i++) {
    cout << std::setfill('0') << std::right << std::setw(6) << numm[i][0]
         << std::setfill('0') << std::right << std::setw(6)
         << py[numm[i][0]][numm[i][1]] << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9 + 7)
#define PI 3.1415926535897932384

template <class T> ostream &operator<<(std::ostream &o, const vector<T> &v) {
  rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; }
  return o;
}

int main() {
  int n, m;
  cin >> n >> m;
  vi place(m), year(m);
  vvi perp(n + 1, vi());
  rep(i, m) {
    cin >> place[i] >> year[i];
    perp[place[i]].push_back(year[i]);
  }
  rep(i, n + 1) {
    if (!perp[i].empty()) {
      sort(all(perp[i]));
    }
  }
  rep(i, m) {
    cout << setfill('0') << setw(6) << right << place[i];
    rep(j, perp[place[i]].size()) {
      if (perp[place[i]][j] == year[i]) {
        cout << setfill('0') << setw(6) << right << j + 1 << endl;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9 + 7)
#define PI 3.1415926535897932384

template <class T> ostream &operator<<(std::ostream &o, const vector<T> &v) {
  rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; }
  return o;
}

int main() {
  int n, m;
  cin >> n >> m;
  vi place(m), year(m);
  vvi perp(n + 1, vi());
  rep(i, m) {
    cin >> place[i] >> year[i];
    perp[place[i]].push_back(year[i]);
  }
  rep(i, n + 1) {
    if (!perp[i].empty()) {
      sort(all(perp[i]));
    }
  }
  rep(i, m) {
    cout << setfill('0') << setw(6) << right << place[i];
    auto itr = lower_bound(all(perp[place[i]]), year[i]);
    cout << setfill('0') << setw(6) << right << itr - perp[place[i]].begin() + 1
         << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int n, m;
int ph1[11000];
int ph2[11000];
int pm[11000];
struct xxx {
  int x;
  int y;
  int id;
} a[1001001];
bool cmp(xxx a, xxx b) {
  if (a.x == b.x)
    return a.y < b.y;
  else
    return a.x < b.x;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> a[i].x >> a[i].y, a[i].id = i;
  sort(a + 1, a + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    pm[a[i].x]++;
    ph1[a[i].id] = a[i].x;
    ph2[a[i].id] = pm[a[i].x];
  }
  for (int i = 1; i <= m; i++) {
    int x, pr = 6;
    x = ph1[i];
    while (x) {
      pr--;
      x /= 10;
    }
    while (pr--)
      printf("0");
    printf("%d", ph1[i]);
    x = ph2[i];
    pr = 6;
    while (x) {
      pr--;
      x /= 10;
    }
    while (pr--)
      printf("0");
    printf("%d\n", ph2[i]);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int n, m;
int ph1[110000];
int ph2[110000];
int pm[110000];
struct xxx {
  int x;
  int y;
  int id;
} a[1001001];
bool cmp(xxx a, xxx b) {
  if (a.x == b.x)
    return a.y < b.y;
  else
    return a.x < b.x;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> a[i].x >> a[i].y, a[i].id = i;
  sort(a + 1, a + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    pm[a[i].x]++;
    ph1[a[i].id] = a[i].x;
    ph2[a[i].id] = pm[a[i].x];
  }
  for (int i = 1; i <= m; i++) {
    int x, pr = 6;
    x = ph1[i];
    while (x) {
      pr--;
      x /= 10;
    }
    while (pr--)
      printf("0");
    printf("%d", ph1[i]);
    x = ph2[i];
    pr = 6;
    while (x) {
      pr--;
      x /= 10;
    }
    while (pr--)
      printf("0");
    printf("%d\n", ph2[i]);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <iomanip> // std::setw(int), std::setfill(char)
#include <ios>     // std::left, std::right

using namespace std;
typedef long long ll;

struct city {
  int num;
  int p;
  int y;
};

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

  sort(c.begin(), c.end(),
       [](auto const &lhs, auto const &rhs) { return lhs.y < rhs.y; });
  /*
  for(auto ci:c){
    cout << "#" << ci.num << " " << ci.p << " " << ci.y << endl;
  }
  */

  vector<int> prefs(m + 1, 0);
  for (auto &ci : c) {
    prefs[ci.p]++;
    ci.y = prefs[ci.p];
  }

  sort(c.begin(), c.end(),
       [](auto const &lhs, auto const &rhs) { return lhs.num < rhs.num; });

  for (auto ci : c) {
    cout << setfill('0') << right << setw(6) << ci.p;
    cout << setfill('0') << right << setw(6) << ci.y;
    cout << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <iomanip> // std::setw(int), std::setfill(char)
#include <ios>     // std::left, std::right

using namespace std;
typedef long long ll;

struct city {
  int num;
  int p;
  int y;
};

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

  sort(c.begin(), c.end(),
       [](auto const &lhs, auto const &rhs) { return lhs.y < rhs.y; });
  /*
  for(auto ci:c){
    cout << "#" << ci.num << " " << ci.p << " " << ci.y << endl;
  }
  */

  vector<int> prefs(n + 1, 0);
  for (auto &ci : c) {
    prefs[ci.p]++;
    ci.y = prefs[ci.p];
  }

  sort(c.begin(), c.end(),
       [](auto const &lhs, auto const &rhs) { return lhs.num < rhs.num; });

  for (auto ci : c) {
    cout << setfill('0') << right << setw(6) << ci.p;
    cout << setfill('0') << right << setw(6) << ci.y;
    cout << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize(3)
namespace ZDY {
#define res register
#define ri res int
#define ll long long
#define db double
#define sht short
#define il inline
#define MB template <class T>
#define Fur(i, x, y) for (ri i = x; i <= y; i++)
#define fur(i, x, y) for (i = x; i <= y; i++)
#define Fdr(i, x, y) for (ri i = x; i >= y; i--)
#define clr(x, y) memset(x, y, sizeof(x))
#define cpy(x, y) memcpy(x, y, sizeof(x))
#define fl(i, x) for (ri i = head[x], to; to = e[i].to, i; i = e[i].nxt)
#define inf 2122219134
#define fin(s) freopen(s ".in", "r", stdin)
#define fout(s) freopen(s ".out", "w", stdin)
#define l2(n) (ceil(log2(n)))
#define fast ios::sync_with_stdio(false)
MB il T ABS(T x) { return x > 0 ? x : -x; }
MB il T MAX(T x, T y) { return x > y ? x : y; }
MB il T MIN(T x, T y) { return x < y ? x : y; }
MB il T GCD(T x, T y) { return y ? GCD(y, x % y) : x; }
} // namespace ZDY
using namespace ZDY;
using namespace std;
#define N 10010
int n, m, a1[N], a2[N];
struct city {
  int id, y;
  friend bool operator<(const city &a, const city &b) { return a.y < b.y; }
};
vector<city> a[N];
int main() {
  cin >> n >> m;
  int p, y;
  Fur(i, 1, m) {
    scanf("%d%d", &p, &y);
    a[p].push_back((city){i, y});
  }
  Fur(i, 1, n) if (!a[i].empty()) {
    sort(a[i].begin(), a[i].end());
    Fur(j, 0, a[i].size() - 1) a1[a[i][j].id] = i, a2[a[i][j].id] = j + 1;
  }
  Fur(i, 1, m) printf("%06d%06d\n", a1[i], a2[i]);
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize(3)
namespace ZDY {
#define res register
#define ri res int
#define ll long long
#define db double
#define sht short
#define il inline
#define MB template <class T>
#define Fur(i, x, y) for (ri i = x; i <= y; i++)
#define fur(i, x, y) for (i = x; i <= y; i++)
#define Fdr(i, x, y) for (ri i = x; i >= y; i--)
#define clr(x, y) memset(x, y, sizeof(x))
#define cpy(x, y) memcpy(x, y, sizeof(x))
#define fl(i, x) for (ri i = head[x], to; to = e[i].to, i; i = e[i].nxt)
#define inf 2122219134
#define fin(s) freopen(s ".in", "r", stdin)
#define fout(s) freopen(s ".out", "w", stdin)
#define l2(n) (ceil(log2(n)))
#define fast ios::sync_with_stdio(false)
MB il T ABS(T x) { return x > 0 ? x : -x; }
MB il T MAX(T x, T y) { return x > y ? x : y; }
MB il T MIN(T x, T y) { return x < y ? x : y; }
MB il T GCD(T x, T y) { return y ? GCD(y, x % y) : x; }
} // namespace ZDY
using namespace ZDY;
using namespace std;
#define N 100010
int n, m, a1[N], a2[N];
struct city {
  int id, y;
  friend bool operator<(const city &a, const city &b) { return a.y < b.y; }
};
vector<city> a[N];
int main() {
  cin >> n >> m;
  int p, y;
  Fur(i, 1, m) {
    scanf("%d%d", &p, &y);
    a[p].push_back((city){i, y});
  }
  Fur(i, 1, n) if (!a[i].empty()) {
    sort(a[i].begin(), a[i].end());
    Fur(j, 0, a[i].size() - 1) a1[a[i][j].id] = i, a2[a[i][j].id] = j + 1;
  }
  Fur(i, 1, m) printf("%06d%06d\n", a1[i], a2[i]);
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, limit) for (int i = 0; i < limit; ++i)
#define LINT long long

int main() {
  int N, M;
  cin >> N >> M;
  pair<int, int> p[M], pp[M];
  int look[1000000001];
  REP(i, M) {
    cin >> p[i].first >> p[i].second;
    pp[i].first = p[i].first;
    pp[i].second = p[i].second;
    look[p[i].second] = i;
  }
  int bangou[M];
  sort(pp, pp + M);

  int work = 1;
  bangou[look[pp[0].second]] = 1;
  REP(i, M - 1) {
    if (pp[i + 1].first == pp[i].first) {
      ++work;
      bangou[look[pp[i + 1].second]] = work;
    } else {
      work = 1;
      bangou[look[pp[i + 1].second]] = work;
    }
  }

  int w;
  REP(i, M) {
    w = look[p[i].second];
    printf("%06d%06d\n", p[w].first, bangou[i]);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, limit) for (int i = 0; i < limit; ++i)
#define LINT long long

int main() {
  int N, M;
  cin >> N >> M;
  pair<int, int> p[M], pp[M];
  map<int, int> look;
  REP(i, M) {
    cin >> p[i].first >> p[i].second;
    pp[i].first = p[i].first;
    pp[i].second = p[i].second;
    look[p[i].second] = i;
  }
  int bangou[M];
  sort(pp, pp + M);

  int work = 1;
  bangou[look[pp[0].second]] = 1;
  REP(i, M - 1) {
    if (pp[i + 1].first == pp[i].first) {
      ++work;
      bangou[look[pp[i + 1].second]] = work;
    } else {
      work = 1;
      bangou[look[pp[i + 1].second]] = work;
    }
  }

  int w;
  REP(i, M) {
    w = look[p[i].second];
    printf("%06d%06d\n", p[w].first, bangou[i]);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct pr {
  int p, y;
};

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m + 1);
  vector<pr> b(m);
  for (int i = 0; i < m; ++i) {
    int p, y;
    cin >> p >> y;
    a.at(p).emplace_back(y);
    b.at(i).p = p, b.at(i).y = y;
  }
  for (auto &&i : a)
    sort(i.begin(), i.end());
  unordered_map<int, int> mp;
  for (int i = 1; i < a.size(); ++i) {
    for (int j = 0; j < a.at(i).size(); ++j) {
      mp[a.at(i).at(j)] = j + 1;
    }
  }
  for (auto &&i : b)
    cout << setfill('0') << setw(6) << i.p << setfill('0') << setw(6)
         << mp.at(i.y) << "\n"s;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct pr {
  int p, y;
};

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n + 1);
  vector<pr> b(m);
  for (int i = 0; i < m; ++i) {
    int p, y;
    cin >> p >> y;
    a.at(p).emplace_back(y);
    b.at(i).p = p, b.at(i).y = y;
  }
  for (auto &&i : a)
    sort(i.begin(), i.end());
  unordered_map<int, int> mp;
  for (int i = 1; i < a.size(); ++i) {
    for (int j = 0; j < a.at(i).size(); ++j) {
      mp[a.at(i).at(j)] = j + 1;
    }
  }
  for (auto &&i : b)
    cout << setfill('0') << setw(6) << i.p << setfill('0') << setw(6)
         << mp.at(i.y) << "\n"s;
}
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<int> P(N), Y(N), ord[100010];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    ord[P[i]].push_back(Y[i]);
  }
  for (int i = 1; i <= N; i++)
    sort(ord[i].begin(), ord[i].end());
  for (int i = 0; i < M; i++) {
    printf("%06d", P[i]);
    int d = lower_bound(ord[P[i]].begin(), ord[P[i]].end(), Y[i]) -
            ord[P[i]].begin() + 1;
    printf("%06d\n", d);
  }
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M), ord[100010];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    ord[P[i]].push_back(Y[i]);
  }
  for (int i = 1; i <= N; i++)
    sort(ord[i].begin(), ord[i].end());
  for (int i = 0; i < M; i++) {
    printf("%06d", P[i]);
    int d = lower_bound(ord[P[i]].begin(), ord[P[i]].end(), Y[i]) -
            ord[P[i]].begin() + 1;
    printf("%06d\n", d);
  }
  return 0;
}
Problem p03221 (C++)

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

using namespace std;

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

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

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

typedef pair<int, int> P;
typedef vector<int> V;
typedef vector<V> VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF ((ll)1 << 63 - 1)
#define INF (1 << 29)
#define MINF -2000000007
#define MAX 100050

const int MOD = 1e9 + 7;
// テンプレ終了
//====================================================================//

//
int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> city(M);
  REP(i, M) {
    cin >> get<0>(city[i]) >> get<1>(city[i]);
    get<2>(city[i]) = 1;
  }

  REP(i, N) {
    V order(M);
    iota(ALL(order), 0);
    sort(ALL(order), [&](int x, int y) { return city[x] < city[y]; });
    int cnt = 1;
    get<2>(city[order[0]]) = cnt++;
    REPS(j, 1, M) {
      if (get<0>(city[order[j - 1]]) != get<0>(city[order[j]]))
        cnt = 1;
      get<2>(city[order[j]]) = cnt++;
    }
  }

  REP(i, M) printf("%06d%06d\n", get<0>(city[i]), get<2>(city[i]));

  return 0;
}


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

using namespace std;

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

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

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

typedef pair<int, int> P;
typedef vector<int> V;
typedef vector<V> VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF ((ll)1 << 63 - 1)
#define INF (1 << 29)
#define MINF -2000000007
#define MAX 100050

const int MOD = 1e9 + 7;
// テンプレ終了
//====================================================================//

//
int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> city(M);
  REP(i, M) {
    cin >> get<0>(city[i]) >> get<1>(city[i]);
    get<2>(city[i]) = 1;
  }

  V order(M);
  iota(ALL(order), 0);
  sort(ALL(order), [&](int x, int y) { return city[x] < city[y]; });
  int cnt = 1;
  get<2>(city[order[0]]) = cnt++;
  REPS(j, 1, M) {
    if (get<0>(city[order[j - 1]]) != get<0>(city[order[j]]))
      cnt = 1;
    get<2>(city[order[j]]) = cnt++;
  }

  REP(i, M) printf("%06d%06d\n", get<0>(city[i]), get<2>(city[i]));

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  map<pair<int, int>, int> rank;
  vector<vector<int>> city(N + 1);
  rep(i, M) {
    int p, y;
    cin >> p >> y;
    P.at(i) = p;
    Y.at(i) = y;
    city.at(p).push_back(y);
  }
  rep(i, M) { sort(city.at(i).begin(), city.at(i).end()); }
  rep(i, N + 1) {
    int r = 1;
    for (int j : city.at(i)) {
      rank[mp(i, j)] = r;
      r++;
    }
  }
  rep(i, M) { printf("%06d%06d\n", P.at(i), rank[mp(P.at(i), Y.at(i))]); }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < int(a); ++i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  map<pair<int, int>, int> rank;
  vector<vector<int>> city(N + 1);
  rep(i, M) {
    int p, y;
    cin >> p >> y;
    P.at(i) = p;
    Y.at(i) = y;
    city.at(p).push_back(y);
  }
  rep(i, N + 1) { sort(city.at(i).begin(), city.at(i).end()); }
  rep(i, N + 1) {
    int r = 1;
    for (int j : city.at(i)) {
      rank[mp(i, j)] = r;
      r++;
    }
  }
  rep(i, M) { printf("%06d%06d\n", P.at(i), rank[mp(P.at(i), Y.at(i))]); }
}
Problem p03221 (C++)

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

#define FOR(i, s, e) for (int i = (s); i < (e); i++)
#define FOR64(i, s, e) for (ll i = (s); i < (e); i++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(b, e) sort((b), (e))
#define REV(b, e) reverse((b), (e))
#define VSORT(v) sort((v).begin(), (v).end())
#define VREV(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 999999999

typedef long long ll;

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

  vector<int> P(M + 1);
  vector<int> Y(M + 1);

  map<int, vector<int>> m;

  FOR(i, 1, M + 1) {
    cin >> P[i] >> Y[i];
    m[P[i]].pb(Y[i]);
  }

  for (auto &e : m) {
    VSORT(e.second);
  }

  FOR(i, 1, M + 1) {
    auto it = find(ALL(m[P[i]]), Y[i]);
    printf("%06d%06d\n", P[i], it - m[P[i]].begin() + 1);
  }

  return 0;
}


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

#define FOR(i, s, e) for (int i = (s); i < (e); i++)
#define FOR64(i, s, e) for (ll i = (s); i < (e); i++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(b, e) sort((b), (e))
#define REV(b, e) reverse((b), (e))
#define VSORT(v) sort((v).begin(), (v).end())
#define VREV(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 999999999

typedef long long ll;

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

  vector<int> P(M + 1);
  vector<int> Y(M + 1);

  map<int, vector<int>> m;

  FOR(i, 1, M + 1) {
    cin >> P[i] >> Y[i];
    m[P[i]].pb(Y[i]);
  }

  for (auto &e : m) {
    VSORT(e.second);
  }

  FOR(i, 1, M + 1) {
    auto &e = m[P[i]];
    auto it = lower_bound(ALL(e), Y[i]);
    printf("%06d%06d\n", P[i], it - e.begin() + 1);
  }

  return 0;
}