prithivMLmods/Coder-Stat huggingface dataset:
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<vector<int>> pre_year(100001);
  vector<int> pre(100001);
  vector<int> year(100001);

  for (int i = 0; i < M; i++) {
    cin >> pre[i] >> year[i];
    pre_year[pre[i]].push_back(year[i]);
    sort(pre_year[pre[i]].begin(), pre_year[pre[i]].end());
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << pre[i];
    auto a =
        lower_bound(pre_year[pre[i]].begin(), pre_year[pre[i]].end(), year[i]);
    string ab = to_string(a - pre_year[pre[i]].begin() + 1);
    cout << setfill('0') << right << setw(6) << ab << endl;
  }
}


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

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

  vector<vector<int>> pre_year(100001);
  vector<int> pre(100001);
  vector<int> year(100001);

  for (int i = 0; i < M; i++) {
    cin >> pre[i] >> year[i];
    pre_year[pre[i]].push_back(year[i]);
  }
  for (int i = 1; i <= N; i++) {
    sort(pre_year[i].begin(), pre_year[i].end());
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << pre[i];
    auto a =
        lower_bound(pre_year[pre[i]].begin(), pre_year[pre[i]].end(), year[i]);
    string ab = to_string(a - pre_year[pre[i]].begin() + 1);
    cout << setfill('0') << right << setw(6) << ab << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long 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())

int main() {
  long long N;
  long long M;
  scanf("%lld", &N);
  scanf("%lld", &M);
  vector<ll> Y(M - 1 + 1);
  vector<ll> P(M - 1 + 1);
  priority_queue<PA, vector<PA>, greater<PA>> que[N];
  for (ll i = 0; i <= M - 1; i++) {
    cin >> P[i];
    cin >> Y[i];
    P[i]--;
    que[P[i]].push(PA(Y[i], i));
  }
  vector<ll> num(N);
  rep(i, N) {
    ll c = 1;
    while (!que[i].empty()) {
      num[que[i].top().second] = c;
      c++;
      que[i].pop();
    }
  }
  rep(i, M) {
    printf("%06lld", P[i] + 1);
    printf("%06lld\n", num[i]);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long 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())

int main() {
  long long N;
  long long M;
  scanf("%lld", &N);
  scanf("%lld", &M);
  vector<ll> Y(M - 1 + 1);
  vector<ll> P(M - 1 + 1);
  priority_queue<PA, vector<PA>, greater<PA>> que[N];
  for (ll i = 0; i <= M - 1; i++) {
    cin >> P[i];
    cin >> Y[i];
    P[i]--;
    que[P[i]].push(PA(Y[i], i));
  }
  vector<ll> num(M);
  rep(i, N) {
    ll c = 1;
    while (!que[i].empty()) {
      num[que[i].top().second] = c;
      c++;
      que[i].pop();
    }
  }
  rep(i, M) {
    printf("%06lld", P[i] + 1);
    printf("%06lld\n", num[i]);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v[n];
  int p[m], y[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    v[--p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(v[i].begin(), v[i].end());
    // v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
  }
  for (int i = 0; i < m; i++) {
    int t = find(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
    printf("%06d%06d\n", p[i] + 1, t + 1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v[n];
  int p[m], y[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    v[--p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(v[i].begin(), v[i].end());
    // v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
  }
  for (int i = 0; i < m; i++) {
    int t = lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
    printf("%06d%06d\n", p[i] + 1, t + 1);
  }
}
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 rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> p(m), y(m);
  vector<vector<ll>> py(n);
  rep(i, m) {
    cin >> p.at(i) >> y.at(i);
    py.at(p.at(i) - 1).push_back(y.at(i));
  }
  rep(i, n) sort(py.at(p.at(i) - 1).begin(), py.at(p.at(i) - 1).end());
  rep(i, m) printf("%012lld\n",
                   ll(p.at(i)) * 1000000 +
                       int(lower_bound(py.at(p.at(i) - 1).begin(),
                                       py.at(p.at(i) - 1).end(), y.at(i)) -
                           py.at(p.at(i) - 1).begin()) +
                       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 rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> p(m), y(m);
  vector<vector<ll>> py(n);
  rep(i, m) {
    cin >> p.at(i) >> y.at(i);
    py.at(p.at(i) - 1).push_back(y.at(i));
  }
  rep(i, n) sort(py.at(i).begin(), py.at(i).end());
  rep(i, m) printf("%012lld\n",
                   ll(p.at(i)) * 1000000 +
                       int(lower_bound(py.at(p.at(i) - 1).begin(),
                                       py.at(p.at(i) - 1).end(), y.at(i)) -
                           py.at(p.at(i) - 1).begin()) +
                       1);

  return 0;
}
Problem p03221 (C++)

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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<pii>> PY(N + 1);
  vector<pii> res(N);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    PY[p].push_back(make_pair(y, i));
  }
  for (int i = 0; i <= N; i++) {
    if (PY[i].size() == 0)
      continue;
    sort(PY[i].begin(), PY[i].end());
    for (int j = 0; j < PY[i].size(); j++)
      res[PY[i][j].second] = make_pair(i, j + 1);
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << res[i].first;
    cout << setfill('0') << right << setw(6) << res[i].second << '\n';
  }
  return 0;
}


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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<pii>> PY(N + 1);
  vector<pii> res(M);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    PY[p].push_back(make_pair(y, i));
  }
  for (int i = 0; i <= N; i++) {
    if (PY[i].size() == 0)
      continue;
    sort(PY[i].begin(), PY[i].end());
    for (int j = 0; j < PY[i].size(); j++)
      res[PY[i][j].second] = make_pair(i, j + 1);
  }
  for (int i = 0; i < M; i++) {
    cout << setfill('0') << right << setw(6) << res[i].first;
    cout << setfill('0') << right << setw(6) << res[i].second << '\n';
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int p[100001], y[100001];
  vector<int> vec[100001];

  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> p[i] >> y[i];
    vec[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < N; i++) {
    sort(vec[i + 1].begin(), vec[i + 1].end());
  }

  for (int i = 0; i < M; i++) {
    printf("%06d", p[i]);
    for (int j = 0; j < vec[p[i]].size(); j++) {
      if (vec[p[i]][j] == y[i]) {
        printf("%06d", j + 1);
        break;
      }
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int p[100001], y[100001];
  vector<int> vec[100001];

  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> p[i] >> y[i];
    vec[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < N; i++) {
    sort(vec[i + 1].begin(), vec[i + 1].end());
  }

  for (int i = 0; i < M; i++) {
    printf("%06d", p[i]);
    int j = lower_bound(vec[p[i]].begin(), vec[p[i]].end(), y[i]) -
            vec[p[i]].begin() + 1;
    printf("%06d", j);
    cout << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int, int>> v;
  for (int i = 1; i <= m; i++) {
    int p, y, x = 0;
    cin >> p >> y;
    v.emplace_back(p, y, x, i);
  }
  sort(v.begin(), v.end());
  int tmp = 0;
  int num = 1;
  for (auto &t : v) {
    if (get<0>(t) != tmp) {
      tmp = get<0>(t);
      num = 1;
      get<2>(t) = num;
      num++;
    } else {
      get<2>(t) = num;
      num++;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (auto t : v) {
      if (get<3>(t) == i) {
        printf("%06d", get<0>(t));
        printf("%06d\n", get<2>(t));
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int, int>> v;
  for (int i = 1; i <= m; i++) {
    int p, y, x = 0;
    cin >> p >> y;
    v.emplace_back(p, y, x, i);
  }
  sort(v.begin(), v.end());
  int tmp = 0;
  int num = 1;
  for (auto &t : v) {
    if (get<0>(t) != tmp) {
      tmp = get<0>(t);
      num = 1;
      get<2>(t) = num;
      num++;
    } else {
      get<2>(t) = num;
      num++;
    }
  }
  vector<tuple<int, int, int, int>> ans(m + 1);
  for (auto t : v) {
    ans[get<3>(t)] = t;
  }
  for (auto t : ans) {
    if (get<0>(t) == 0)
      continue;
    printf("%06d", get<0>(t));
    printf("%06d\n", get<2>(t));
  }
}
Problem p03221 (C++)

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

using namespace std;

int main() {
  // 入力
  long N, M;
  cin >> N >> M;
  vector<long> P(M);
  vector<pair<pair<long, long>, long>> cities(M);

  for (long i = 0; i < M; i++) {
    long Y;
    cin >> P[i] >> Y;
    cities[i] = make_pair(make_pair(Y, P[i]), i);
  }

  // 昇順にソート
  sort(cities.begin(), cities.end());

  vector<long> number(M);
  vector<long> count(N);
  for (long i = 0; i < cities.size(); i++) {
    // 県に属した市iのカウントを計算する
    count[cities[i].first.second]++;
    // 入力時の順番のindexの番号配列に対して、カウントを代入する
    number[cities[i].second] = count[cities[i].first.second];
  }

  // 出力
  for (long i = 0; i < M; i++) {
    // ゼロ埋め対応
    cout << setfill('0') << right << setw(6) << P[i];
    cout << setfill('0') << right << setw(6) << number[i];
    // 改行
    cout << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  // 入力
  long N, M;
  cin >> N >> M;
  vector<long> P(M);
  vector<pair<pair<long, long>, long>> cities(M);

  for (long i = 0; i < M; i++) {
    long Y;
    cin >> P[i] >> Y;
    cities[i] = make_pair(make_pair(Y, P[i]), i);
  }

  // 昇順にソート
  sort(cities.begin(), cities.end());

  vector<long> number(M);
  vector<long> count(N + 1);
  for (long i = 0; i < cities.size(); i++) {
    // 県に属した市iのカウントを計算する
    count[cities[i].first.second]++;
    // 入力時の順番のindexの番号配列に対して、カウントを代入する
    number[cities[i].second] = count[cities[i].first.second];
  }

  // 出力
  for (long i = 0; i < M; i++) {
    // ゼロ埋め対応
    cout << setfill('0') << right << setw(6) << P[i];
    cout << setfill('0') << right << setw(6) << number[i];
    // 改行
    cout << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
ll b[100000];
ll a[100000];
vector<ll> v[100000];
int main() {
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].push_back(b[i]);
  }
  for (ll i = 1; i <= n; i++)
    sort(v[i].begin(), v[i].end());

  for (ll i = 0; i < m; i++) {
    ll ans =
        lower_bound(v[a[i]].begin(), v[a[i]].end(), b[i]) - v[a[i]].begin();
    printf("%06lld%06lld\n", a[i], ans + 1);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
ll b[100010];
ll a[100010];
vector<ll> v[100010];
int main() {
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].push_back(b[i]);
  }
  for (ll i = 1; i <= n; i++)
    sort(v[i].begin(), v[i].end());

  for (ll i = 0; i < m; i++) {
    ll ans =
        lower_bound(v[a[i]].begin(), v[a[i]].end(), b[i]) - v[a[i]].begin();
    printf("%06lld%06lld\n", a[i], ans + 1);
  }

  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++)
using namespace std;
typedef long long ll;

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

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

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

  rep(i, m) cin >> p[i] >> y[i];

  vector<vector<int>> cor(n + 1);
  rep(i, m) { cor[p[i]].push_back(y[i]); }

  rep(i, m) sort(cor[i].begin(), cor[i].end());
  rep(i, m) {
    int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
              cor[p[i]].begin() + 1;
    cout << setfill('0') << setw(6) << p[i] << setfill('0') << setw(6) << num
         << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;

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

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

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

  rep(i, m) cin >> p[i] >> y[i];

  vector<vector<int>> cor(n + 1);
  rep(i, m) { cor[p[i]].push_back(y[i]); }

  for (int i = 1; i <= n; i++)
    sort(cor[i].begin(), cor[i].end());
  rep(i, m) {
    int num = lower_bound(cor[p[i]].begin(), cor[p[i]].end(), y[i]) -
              cor[p[i]].begin() + 1;
    cout << setfill('0') << setw(6) << p[i] << setfill('0') << setw(6) << num
         << endl;
  }
}
Problem p03221 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<ll, ll>>> p(m, vector<pair<ll, ll>>(0));
  vector<string> id(m);
  for (int i = 0; i < m; i++) {
    ll place, year;
    cin >> place >> year;
    p[place - 1].push_back(make_pair(year, i));
  }
  for (int i = 0; i < n; i++) {
    sort(p[i].begin(), p[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < p[i].size(); j++) {
      ostringstream ss;
      ss << setw(6) << setfill('0') << to_string(i + 1);
      string idi(ss.str());
      ostringstream sl;
      sl << setw(6) << setfill('0') << to_string(j + 1);
      string idj(sl.str());
      id[p[i][j].second] = idi + idj;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << id[i] << endl;
  }
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<ll, ll>>> p(n, vector<pair<ll, ll>>(0));
  vector<string> id(m);
  for (int i = 0; i < m; i++) {
    ll place, year;
    cin >> place >> year;
    p[place - 1].push_back(make_pair(year, i));
  }
  for (int i = 0; i < n; i++) {
    sort(p[i].begin(), p[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < p[i].size(); j++) {
      ostringstream ss;
      ss << setw(6) << setfill('0') << to_string(i + 1);
      string idi(ss.str());
      ostringstream sl;
      sl << setw(6) << setfill('0') << to_string(j + 1);
      string idj(sl.str());
      id[p[i][j].second] = idi + idj;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << id[i] << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x), 0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);

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;
}

int main() {
  int n, m;
  cin >> n >> m;
  vi p(m), y(m);
  vi yd[m + 1];
  rep(i, m) {
    cin >> p[i] >> y[i];
    yd[p[i]].pb(y[i]);
  }
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%06d%06d\n", p[i],
                   lower_bound(rng(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x), 0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);

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;
}

int main() {
  int n, m;
  cin >> n >> m;
  vi p(m), y(m);
  vi yd[n + 1];
  rep(i, m) {
    cin >> p[i] >> y[i];
    yd[p[i]].pb(y[i]);
  }
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%06d%06d\n", p[i],
                   lower_bound(rng(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1);
  return 0;
}
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<vector<int>> vec(n);
  vector<pair<int, int>> city(m);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    vec[p - 1].push_back(y);
    city[i] = make_pair(p - 1, y);
  }
  for (int i = 0; i < n; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  for (auto &e : city) {
    int p = e.first, y = e.second;
    auto itr = find(vec[p].begin(), vec[p].end(), y);
    printf("%06d", p + 1);
    printf("%06d", (int)(itr - vec[p].begin()) + 1);
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(n);
  vector<pair<int, int>> city(m);
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    vec[p - 1].push_back(y);
    city[i] = make_pair(p - 1, y);
  }
  for (int i = 0; i < n; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  for (auto &e : city) {
    int p = e.first, y = e.second;
    auto itr = lower_bound(vec[p].begin(), vec[p].end(), y);
    printf("%06d", p + 1);
    printf("%06d", (int)(itr - vec[p].begin()) + 1);
    cout << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char *argv[]) {
  //    ifstream in("input.txt");
  //    cin.rdbuf(in.rdbuf());

  cin.tie(0);
  ios::sync_with_stdio(false);

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

  vector<tuple<int, int, int>> p_yip(m); // year, id, prefecture

  rep(i, m) {
    int p, y;
    cin >> p >> y;
    --p;
    p_yip[i] = {y, i, p};
  }

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

  vector<vector<int>> table(m); // [prefecture][city_id]
  rep(i, m) { table[get<2>(p_yip[i])].push_back(get<1>(p_yip[i])); }

  vector<string> vec_ans(m);

  rep(prefecture, n) {
    std::ostringstream sout_p;
    sout_p << std::setfill('0') << std::setw(6) << prefecture + 1;
    std::string str_p = sout_p.str();

    for (int city = 0; city < table[prefecture].size(); ++city) {
      std::ostringstream sout_c;
      sout_c << std::setfill('0') << std::setw(6) << city + 1;
      std::string str_c = sout_c.str();

      vec_ans[table[prefecture][city]] = str_p + str_c;
    }
  }

  rep(i, m) { cout << vec_ans[i] << endl; }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char *argv[]) {
  //    ifstream in("input.txt");
  //    cin.rdbuf(in.rdbuf());

  cin.tie(0);
  ios::sync_with_stdio(false);

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

  vector<tuple<int, int, int>> p_yip(m); // year, id, prefecture

  rep(i, m) {
    int p, y;
    cin >> p >> y;
    --p;
    p_yip[i] = {y, i, p};
  }

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

  vector<vector<int>> table(n); // [prefecture][city] -> city_id
  rep(i, m) { table[get<2>(p_yip[i])].push_back(get<1>(p_yip[i])); }

  vector<string> vec_ans(m);

  rep(prefecture, n) {
    std::ostringstream sout_p;
    sout_p << std::setfill('0') << std::setw(6) << prefecture + 1;
    std::string str_p = sout_p.str();

    for (int city = 0; city < table[prefecture].size(); ++city) {
      std::ostringstream sout_c;
      sout_c << std::setfill('0') << std::setw(6) << city + 1;
      std::string str_c = sout_c.str();

      vec_ans[table[prefecture][city]] = str_p + str_c;
    }
  }

  rep(i, m) { cout << vec_ans[i] << endl; }

  return 0;
}
Problem p03221 (C++)

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<long long, long long>, long long>> ypx(m);
  vector<long long> ans(m);
  vector<long long> cnt(n);
  for (int i = 0; i < m; ++i) {
    cin >> ypx[i].first.second >> ypx[i].first.first;
    ypx[i].second = i;
  }
  sort(ypx.begin(), ypx.end());
  for (int i = 0; i < m; ++i) {
    long long pi = ypx[i].first.second;
    cnt[pi]++;
    ans[ypx[i].second] = pi * 1000000 + cnt[pi];
  }
  for (int i = 0; i < m; ++i)
    printf("%012lld\n", ans[i]);

  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<long long, long long>, long long>> ypx(m);
  vector<long long> ans(m);
  vector<long long> cnt(n + 1);
  for (int i = 0; i < m; ++i) {
    cin >> ypx[i].first.second >> ypx[i].first.first;
    ypx[i].second = i;
  }
  sort(ypx.begin(), ypx.end());
  for (int i = 0; i < m; ++i) {
    long long pi = ypx[i].first.second;
    cnt[pi]++;
    ans[ypx[i].second] = pi * 1000000 + cnt[pi];
  }
  for (int i = 0; i < m; ++i)
    printf("%012lld\n", ans[i]);

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#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 pair<int, Pii> P1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yd[100001];
  rep(i, m) {
    int pi, yi;
    cin >> pi >> yi;
    p[i] = pi;
    y[i] = yi;
    yd[pi].push_back(yi);
  }
  // 上記コードは1行で済む。
  // rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
  rep(i, n) sor(yd[i + 1]);
  rep(i, m) {
    vector<ll> ydp = yd[p[i]]; // autoにすると4倍かかる
    int index = int(lb(ydp, y[i]) - ydp.begin()) + 1;
    printf("%012lld\n", ll(p[i]) * 1000000 + index);
  }
  return 0;
}


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 pair<int, Pii> P1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yd[100001];
  rep(i, m) {
    int pi, yi;
    cin >> pi >> yi;
    p[i] = pi;
    y[i] = yi;
    yd[pi].push_back(yi);
  }
  // 上記コードは1行で済む。
  // rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
  rep(i, n) sor(yd[i + 1]);
  rep(i, m) {
    // vector<ll> ydp = yd[p[i]]; => コピーされるのでNG。TLEを起こす。
    vector<ll> *ydp = &yd[p[i]];
    int index =
        int(lower_bound(ydp->begin(), ydp->end(), y[i]) - ydp->begin()) + 1;
    printf("%012lld\n", ll(p[i]) * 1000000 + index);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#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 pair<int, Pii> P1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yd[100001];
  rep(i, m) {
    int pi, yi;
    cin >> pi >> yi;
    p[i] = pi;
    y[i] = yi;
    yd[pi].push_back(yi);
  }
  // rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
  rep(i, n) sor(yd[i + 1]);
  rep(i, m) {
    auto year = yd[p[i]];
    int index = int(lb(year, y[i]) - year.begin()) + 1;
    printf("%012lld\n", ll(p[i]) * 1000000 + index);
  }
  // printf ("%012lld\n", ll(p[i])*1000000+ int(lb(yd[p[i]], y[i]) -
  // yd[p[i]].begin())+1);
  return 0;
}


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 pair<int, Pii> P1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yd[100001];
  rep(i, m) {
    int pi, yi;
    cin >> pi >> yi;
    p[i] = pi;
    y[i] = yi;
    yd[pi].push_back(yi);
  }
  // rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
  rep(i, n) sor(yd[i + 1]);
  rep(i, m) {
    int index = int(lb(yd[p[i]], y[i]) - yd[p[i]].begin()) + 1;
    printf("%012lld\n", ll(p[i]) * 1000000 + index);
  }
  // printf ("%012lld\n", ll(p[i])*1000000+ int(lb(yd[p[i]], y[i]) -
  // yd[p[i]].begin())+1);
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#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 pair<int, Pii> P1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yearList[100001];
  rep(i, m) {
    int pi, yi;
    cin >> pi >> yi;
    p[i] = pi;
    y[i] = yi;
    yearList[pi].push_back(yi);
  }
  rep(i, n) sor(yearList[i + 1]);
  rep(i, m) {
    // cout.fill('0');
    // cout << setw(6) << p[i];
    auto year = yearList[p[i]];
    int index = int(lb(year, y[i]) - year.begin()) + 1;
    // cout << setw(6) << index << endl;
    printf("%012lld\n", ll(p[i]) * 1000000 + index);
  }
  return 0;
}


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 pair<int, Pii> P1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define mp1(a, b, c) P1(a, P(b, c))
#define get_arsize(a) (sizeof(a) / sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yd[100001];
  rep(i, m) scanf("%d%d", &p[i], &y[i]), yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%012lld\n",
                   ll(p[i]) * 1000000 +
                       int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                           yd[p[i]].begin()) +
                       1);
  return 0;
}
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(M), Y(M);

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

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

  for (int i = 0; i < M; i++) {
    vals[P[i]].push_back(Y[i]);
  }

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

  for (int i = 0; i < M; i++) {
    int v = P[i];
    printf("%06d", v + 1);
    int id =
        lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
    printf("%06d\n", id + 1);
  }
}

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);

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

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

  for (int i = 0; i < M; i++) {
    vals[P[i]].push_back(Y[i]);
  }

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

  for (int i = 0; i < M; i++) {
    int v = P[i];
    printf("%06d", v + 1);
    int id =
        lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
    printf("%06d\n", id + 1);
  }
}
Problem p03221 (C++)

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

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main() {
  int N, M;
  vector<int> tmp[N + 1];
  int P[100000], Y[100000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    tmp[P[i]].push_back(Y[i]);
  }

  for (int i = 0; i < N; i++) {
    sort(tmp[i + 1].begin(), tmp[i + 1].end());
  }

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main() {
  int N, M;
  vector<int> tmp[100001];
  int P[100000], Y[100000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    tmp[P[i]].push_back(Y[i]);
  }

  for (int i = 0; i < N; i++) {
    sort(tmp[i + 1].begin(), tmp[i + 1].end());
  }

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

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

  vector<vector<pair<ll, ll>>> v(
      n +
      1); // v[i][j] : 県i(iは1-index)に属する市の中でj番目に早く誕生した市の
          // (誕生年, 市の番号)
  exrep(i, 1, m) {
    ll p, y;
    cin >> p >> y;
    v[p].pb(make_pair(y, i));
  }

  exrep(i, 1, n) {
    if (v[i].size() == 0) {
      continue;
    }
    sort(all(v[i]));
  }

  vector<pair<ll, ll>> w(
      n +
      1); // w[i] : 市i(iは1-index)の (属する県の番号, その県の中で誕生した順番)
  exrep(i, 1, n) {
    rep(j, v[i].size()) {
      ll k = v[i][j].second;
      w[k] = make_pair(i, j + 1);
    }
  }

  exrep(i, 1, m) {
    ll A = w[i].first;
    ll B = w[i].second;
    printf("%06lld", A);
    printf("%06lld\n", B);
  }

  re0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

  vector<vector<pair<ll, ll>>> v(
      n +
      1); // v[i][j] : 県i(iは1-index)に属する市の中でj番目に早く誕生した市の
          // (誕生年, 市の番号)
  exrep(i, 1, m) {
    ll p, y;
    cin >> p >> y;
    v[p].pb(make_pair(y, i));
  }

  exrep(i, 1, n) {
    if (v[i].size() == 0) {
      continue;
    }
    sort(all(v[i]));
  }

  vector<pair<ll, ll>> w(
      m +
      1); // w[i] : 市i(iは1-index)の (属する県の番号, その県の中で誕生した順番)
  exrep(i, 1, n) {
    rep(j, v[i].size()) {
      ll k = v[i][j].second;
      w[k] = make_pair(i, j + 1);
    }
  }

  exrep(i, 1, m) {
    ll A = w[i].first;
    ll B = w[i].second;
    printf("%06lld", A);
    printf("%06lld\n", B);
  }

  re0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;

int digit(int x) {
  int ans = 0;
  while (x > 0) {
    ++ans;
    x /= 10;
  }
  return ans;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> SHI(M);
  vector<int> P(M);
  rep(i, M) {
    int p, Y;
    cin >> p >> Y;
    P[i] = p;
    SHI[p - 1].push_back(make_pair(Y, i));
  }
  rep(i, N) sort(SHI[i].begin(), SHI[i].end());
  vector<int> last(M);
  rep(i, N) rep(j, SHI[i].size()) { last[SHI[i][j].second] = j + 1; }

  rep(i, M) {
    rep(j, 6 - digit(P[i])) cout << 0;
    cout << P[i];
    rep(j, 6 - digit(last[i])) cout << 0;
    cout << last[i] << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;

int digit(int x) {
  int ans = 0;
  while (x > 0) {
    ++ans;
    x /= 10;
  }
  return ans;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> SHI(N);
  vector<int> P(M);
  rep(i, M) {
    int p, Y;
    cin >> p >> Y;
    P[i] = p;
    SHI[p - 1].push_back(make_pair(Y, i));
  }
  rep(i, N) sort(SHI[i].begin(), SHI[i].end());
  vector<int> last(M);
  rep(i, N) rep(j, SHI[i].size()) { last[SHI[i][j].second] = j + 1; }

  rep(i, M) {
    rep(j, 6 - digit(P[i])) cout << 0;
    cout << P[i];
    rep(j, 6 - digit(last[i])) cout << 0;
    cout << last[i] << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int N, M;
  scanf("%d%d", &N, &M);
  int PREF[100001];
  int YEAR[100001];
  vector<int> MAP[100001];
  rep(i, M) {
    scanf("%d%d", &PREF[i], &YEAR[i]);
    MAP[PREF[i]].push_back(YEAR[i]);
  }
  rep(i, N) { sort(MAP[i + 1].begin(), MAP[i + 1].end()); }

  rep(i, M) {
    int P, Y;
    P = PREF[i];
    Y = YEAR[i];
    auto B = MAP[P].begin();
    auto j = find(B, end(MAP[P]), Y);
    printf("%012ld\n", (ll)P * 1000000 + (int)(j - B) + 1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int N, M;
  scanf("%d%d", &N, &M);
  int PREF[100001];
  int YEAR[100001];
  vector<int> MAP[100001];
  rep(i, M) {
    scanf("%d%d", &PREF[i], &YEAR[i]);
    MAP[PREF[i]].push_back(YEAR[i]);
  }
  rep(i, N) { sort(MAP[i + 1].begin(), MAP[i + 1].end()); }

  rep(i, M) {
    int P, Y;
    P = PREF[i];
    Y = YEAR[i];
    auto B = MAP[P].begin();
    auto j = lower_bound(B, end(MAP[P]), Y);
    printf("%012ld\n", (ll)P * 1000000 + (int)(j - B) + 1);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

  for (int i = 1; i <= M; i++) {
    int x, y;
    cin >> x >> y;
    P[i] = x;
    city[i] = y;
    Ms[x].push_back(y);
  }

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

  for (int i = 1; i <= M; i++) {
    cout << setfill('0') << setw(6) << right << P[i];
    auto ite = lower_bound(Ms[P[i]].begin(), Ms[P[i]].end(), city[i]);
    cout << setfill('0') << setw(6) << right << ite - Ms[P[i]].begin() + 1;
    cout << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

  for (int i = 1; i <= M; i++) {
    int x, y;
    cin >> x >> y;
    P[i] = x;
    city[i] = y;
    Ms[x].push_back(y);
  }

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

  for (int i = 1; i <= M; i++) {
    cout << setfill('0') << setw(6) << right << P[i];
    auto ite = lower_bound(Ms[P[i]].begin(), Ms[P[i]].end(), city[i]);
    cout << setfill('0') << setw(6) << right << ite - Ms[P[i]].begin() + 1;
    cout << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }

int output(int i) {
  if (i < 10) {
    cout << "00000" << i;
  } else if (i < 100) {
    cout << "0000" << i;
  } else if (i < 1000) {
    cout << "000" << i;
  } else if (i < 10000) {
    cout << "00" << i;
  } else if (i < 100000) {
    cout << "0" << i;
  } else {
    cout << i;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> simo(n + 1);
  vector<int> pre(n + 1);
  vector<int> ban(n + 1);
  for (int i = 1; i <= m; i++) {
    int p, y;
    cin >> p >> y;
    simo[p].push_back(make_pair(y, i));
    pre[i] = p;
  }
  for (int i = 1; i <= n; i++) {
    sort(simo[i].begin(), simo[i].end(), cmp);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < simo[i].size(); j++) {
      ban[simo[i][j].second] = j + 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    output(pre[i]);
    output(ban[i]);
    cout << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }

int output(int i) {
  if (i < 10) {
    cout << "00000" << i;
  } else if (i < 100) {
    cout << "0000" << i;
  } else if (i < 1000) {
    cout << "000" << i;
  } else if (i < 10000) {
    cout << "00" << i;
  } else if (i < 100000) {
    cout << "0" << i;
  } else {
    cout << i;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> simo(n + 1);
  vector<int> pre(m + 1);
  vector<int> ban(m + 1);
  for (int i = 1; i <= m; i++) {
    int p, y;
    cin >> p >> y;
    simo[p].push_back(make_pair(y, i));
    pre[i] = p;
  }
  for (int i = 1; i <= n; i++) {
    sort(simo[i].begin(), simo[i].end(), cmp);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < simo[i].size(); j++) {
      ban[simo[i][j].second] = j + 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    output(pre[i]);
    output(ban[i]);
    cout << endl;
  }
}
Problem p03221 (C++)

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

string encode(int i) {
  string num = to_string(i);
  while (num.size() < 6) {
    num = '0' + num;
  }
  return num;
}

int main() {

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> s(m);
  vector<int> p[n + 1];

  rep(i, m) {
    cin >> s[i].first >> s[i].second;
    p[s[i].first].push_back(s[i].second);
  }
  rep(i, m) { sort(p[i].begin(), p[i].end()); }
  for (int i = 0; i < m; i++) {
    auto it =
        lower_bound(p[s[i].first].begin(), p[s[i].first].end(), s[i].second);
    int t = distance(p[s[i].first].begin(), it);
    string ans = encode(s[i].first) + encode(t + 1);
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < n; ++i)
typedef long long int ll;

string encode(int i) {
  string num = to_string(i);
  while (num.size() < 6) {
    num = '0' + num;
  }
  return num;
}

int main() {

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> s(m);
  vector<int> p[n + 1];

  rep(i, m) {
    cin >> s[i].first >> s[i].second;
    p[s[i].first].push_back(s[i].second);
  }
  rep(i, n + 1) { sort(p[i].begin(), p[i].end()); }
  for (int i = 0; i < m; i++) {
    auto it =
        lower_bound(p[s[i].first].begin(), p[s[i].first].end(), s[i].second);
    int t = distance(p[s[i].first].begin(), it);
    string ans = encode(s[i].first) + encode(t + 1);
    cout << ans << endl;
  }

  return 0;
}
Problem p03221 (C++)

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  rep(i, M) cin >> P[i] >> Y[i];
  vector<int> C[N + 1];
  rep(i, M) C[P[i]].push_back(Y[i]);
  rep(i, N + 1) sort(C[i].begin(), C[i].end());

  rep(i, M) {
    cout << setfill('0') << setw(6) << P[i];
    int id = find(C[P[i]].begin(), C[P[i]].end(), Y[i]) - C[P[i]].begin() + 1;
    cout << setfill('0') << setw(6) << id << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  rep(i, M) cin >> P[i] >> Y[i];
  vector<int> C[N + 1];
  rep(i, M) C[P[i]].push_back(Y[i]);
  rep(i, N + 1) sort(C[i].begin(), C[i].end());

  rep(i, M) {
    cout << setfill('0') << setw(6) << P[i];
    int id =
        lower_bound(C[P[i]].begin(), C[P[i]].end(), Y[i]) - C[P[i]].begin() + 1;
    cout << setfill('0') << setw(6) << id << endl;
  }
  return 0;
}