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

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

void solve(long long N, long long M, std::vector<long long> P,
           std::vector<long long> Y) {
  map<ll, vector<ll>> PYmap;
  for (ll i = 0; i < M; ++i) {
    PYmap[P[i]].push_back(Y[i]);
  }
  for (auto &&m : PYmap) {
    sort(begin(m.second), end(m.second));
  }
  for (ll i = 0; i < M; ++i) {
    auto &Pcities = PYmap[P[i]];
    auto it = find(begin(Pcities), end(Pcities), Y[i]);
    auto x = distance(begin(Pcities), it) + 1;
    printf("%06lld%06ld\n", P[i], x);
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> P(M);
    std::vector<long long> Y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&P[i]);
        scanf("%lld",&Y[i]);
    }
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(N, M, std::move(P), std::move(Y));
    return 0;
}


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

void solve(long long N, long long M, std::vector<long long> P,
           std::vector<long long> Y) {
  map<ll, vector<ll>> PYmap;
  for (ll i = 0; i < M; ++i) {
    PYmap[P[i]].push_back(Y[i]);
  }
  for (auto &&m : PYmap) {
    sort(begin(m.second), end(m.second));
  }
  for (ll i = 0; i < M; ++i) {
    auto &Pcities = PYmap[P[i]];
    auto it = lower_bound(begin(Pcities), end(Pcities), Y[i]);
    auto x = distance(begin(Pcities), it) + 1;
    printf("%06lld%06ld\n", P[i], x);
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> P(M);
    std::vector<long long> Y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&P[i]);
        scanf("%lld",&Y[i]);
    }
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(N, M, std::move(P), std::move(Y));
    return 0;
}
Problem p03221 (C++)

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

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

  vector<int> p(n), y(n);
  vector<vector<int>> data(
      n); // (prefecture, year), be careful with the initialization...
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    data[p[i] - 1].push_back(y[i]);
  }

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

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

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

  vector<long long int> p(m), y(m);
  vector<vector<long long int>> data(
      n); // (prefecture, year), be careful with the initialization...
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    data[p[i] - 1].push_back(y[i]);
  }

  for (int i = 0; i < n; i++) {
    sort(data[i].begin(), data[i].end());
  }
  for (int i = 0; i < m; i++) {
    cout << setw(6) << setfill('0') << p[i] << setw(6) << setfill('0')
         << lower_bound(data[p[i] - 1].begin(), data[p[i] - 1].end(), y[i]) -
                data[p[i] - 1].begin() + 1
         << endl;
  }
  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(n + 1);
  vector<int> y(m + 1);
  vector<int> id[n + 1];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    id[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(id[i + 1].begin(), id[i + 1].end());
  }
  for (int i = 0; i < m; i++) {
    printf("%012lld\n",
           (long long)(p[i]) * 1000000 +
               (long long)(lower_bound(id[p[i]].begin(), id[p[i]].end(), y[i]) -
                           id[p[i]].begin() + 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 + 1);
  vector<int> y(m + 1);
  vector<int> id[n + 1];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    id[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(id[i + 1].begin(), id[i + 1].end());
  }
  for (int i = 0; i < m; i++) {
    printf("%012lld\n",
           (long long)(p[i]) * 1000000 +
               (long long)(lower_bound(id[p[i]].begin(), id[p[i]].end(), y[i]) -
                           id[p[i]].begin() + 1));
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
// #include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <utility>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;

const int MAXN = 1e2 + 5, INF = 1e9;

int n, m;

pair<int, int> inp[MAXN];

vector<int> a[MAXN];

string makeID(int x) {
  string s = "";
  while (x) {
    s.push_back((x % 10) + '0');
    x /= 10;
  }
  while (s.length() < 6) {
    s.push_back('0');
  }
  reverse(s.begin(), s.end());
  return s;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> inp[i].first >> inp[i].second;
    a[inp[i].first - 1].emplace_back(inp[i].second);
  }
  for (int i = 0; i < n; ++i) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; i < m; ++i) {
    int x = lower_bound(a[inp[i].first - 1].begin(), a[inp[i].first - 1].end(),
                        inp[i].second) -
            a[inp[i].first - 1].begin();
    cout << makeID(inp[i].first) << makeID(x + 1) << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
// #include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <utility>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;

const int MAXN = 1e5 + 5, INF = 1e9;

int n, m;

pair<int, int> inp[MAXN];

vector<int> a[MAXN];

string makeID(int x) {
  string s = "";
  while (x) {
    s.push_back((x % 10) + '0');
    x /= 10;
  }
  while (s.length() < 6) {
    s.push_back('0');
  }
  reverse(s.begin(), s.end());
  return s;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> inp[i].first >> inp[i].second;
    a[inp[i].first - 1].emplace_back(inp[i].second);
  }
  for (int i = 0; i < n; ++i) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; i < m; ++i) {
    int x = lower_bound(a[inp[i].first - 1].begin(), a[inp[i].first - 1].end(),
                        inp[i].second) -
            a[inp[i].first - 1].begin();
    cout << makeID(inp[i].first) << makeID(x + 1) << endl;
  }
  return 0;
}
Problem p03221 (C++)

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

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

  vector<int> p(M, 0);
  vector<int> yp(M, 0);
  vector<vector<int>> y(N, vector<int>(0, 0));

  for (int i = 0; i < M; ++i) {
    int tmp_p, tmp_y;
    cin >> tmp_p >> tmp_y;
    --tmp_p;
    p[i] = tmp_p;
    yp[i] = tmp_y;
    y[tmp_p].push_back(tmp_y);
  }

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

  for (int i = 0; i < M; ++i) {
    std::vector<int>::iterator it = find(y[p[i]].begin(), y[p[i]].end(), yp[i]);
    int index = distance(y[p[i]].begin(), it);
    cout << setw(6) << setfill('0') << p[i] + 1;
    cout << setw(6) << setfill('0') << index + 1 << endl;
  }

  return 0;
}


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

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

  vector<int> p(M, 0);
  vector<int> yp(M, 0);
  vector<vector<int>> y(N, vector<int>(0, 0));

  for (int i = 0; i < M; ++i) {
    int tmp_p, tmp_y;
    cin >> tmp_p >> tmp_y;
    --tmp_p;
    p[i] = tmp_p;
    yp[i] = tmp_y;
    y[tmp_p].push_back(tmp_y);
  }

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

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

  return 0;
}
Problem p03221 (C++)

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;
typedef pair<int, int> P;

int main() {

  int n, m;
  cin >> n >> m;
  int p[m + 10], y[m + 10];
  P num[m + 10];
  rep(i, 0, m) {
    cin >> p[i] >> y[i];
    num[i].second = p[i];
    num[i].first = y[i];
  }

  sort(num, num + m);

  vector<int> v[100010];

  rep(i, 0, m) { v[num[i].second - 1].push_back(num[i].first); }

  string digit[] = {"00000", "0000", "000", "00", "0", ""};

  rep(i, 0, m) {
    string s = to_string(p[i]);

    vector<int>::iterator pn =
        find(v[p[i] - 1].begin(), v[p[i] - 1].end(), y[i]);
    size_t index = distance(v[p[i] - 1].begin(), pn);

    string t = to_string(index + 1);

    cout << digit[s.size() - 1] << s << digit[t.size() - 1] << t << endl;
  }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;
typedef pair<int, int> P;

int main() {

  int n, m;
  cin >> n >> m;
  int p[m + 10], y[m + 10];
  P num[m + 10];
  rep(i, 0, m) {
    cin >> p[i] >> y[i];
    num[i].second = p[i];
    num[i].first = y[i];
  }

  sort(num, num + m);

  vector<int> v[100010];

  rep(i, 0, m) { v[num[i].second - 1].push_back(num[i].first); }

  string digit[] = {"00000", "0000", "000", "00", "0", ""};

  rep(i, 0, m) {
    string s = to_string(p[i]);

    int index = upper_bound(v[p[i] - 1].begin(), v[p[i] - 1].end(), y[i]) -
                v[p[i] - 1].begin();
    string t = to_string(index);

    cout << digit[s.size() - 1] << s << digit[t.size() - 1] << t << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<ll> P(m), Y(m);
  vector<set<pair<ll, int>>> C(n);
  rep(i, m) {
    cin >> P[i] >> Y[i];
    P[i]--;
    C[P[i]].emplace(Y[i], i);
  }
  vector<int> ans(n);
  rep(i, n) {
    int j = 1;
    for (auto ele : C[i])
      ans[ele.second] = j++;
  }
  rep(i, m) {
    cout << setfill('0') << right << setw(6) << P[i] + 1;
    cout << setfill('0') << right << setw(6) << ans[i];
    cout << "\n";
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<ll> P(m), Y(m);
  vector<set<pair<ll, int>>> C(n);
  rep(i, m) {
    cin >> P[i] >> Y[i];
    P[i]--;
    C[P[i]].emplace(Y[i], i);
  }
  vector<int> ans(m);
  rep(i, n) {
    int j = 1;
    for (auto ele : C[i])
      ans[ele.second] = j++;
  }
  rep(i, m) {
    cout << setfill('0') << right << setw(6) << P[i] + 1;
    cout << setfill('0') << right << setw(6) << ans[i];
    cout << "\n";
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b) {
  if (b == 0)
    return a;
  if (a < b)
    return GCD(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int binary_search_index(Int Y, vi q) {
  int left = 0, right = q.size() - 1;
  while (right >= left) {
    int mid = left + (right - left) / 2;
    if (q[mid] == Y)
      return mid;
    else if (q[mid] > Y)
      right = mid - 1;
    else if (q[mid] < Y)
      left = mid + 1;
  }
  return -1;
}

int main() {
  Int N, M;
  cin >> N >> M;
  vi P = vi(M);
  vi Y = vi(M);
  rep(i, M) {
    cin >> P[i];
    cin >> Y[i];
  }

  map<Int, vi> mp;
  rep(i, M) { mp[P[i]].push_back(Y[i]); }

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

  rep(i, M) {
    stringstream ans;
    Int yi = binary_search_index(Y[i], mp[P[i]]) + 1;
    ans << std::setw(6) << std::setfill('0') << P[i];
    ans << std::setw(6) << std::setfill('0') << yi;
    cout << ans.str() << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b) {
  if (b == 0)
    return a;
  if (a < b)
    return GCD(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
int binary_search_index(Int Y, vi &q) {
  int left = 0, right = q.size() - 1;
  while (right >= left) {
    int mid = left + (right - left) / 2;
    if (q[mid] == Y)
      return mid;
    else if (q[mid] > Y)
      right = mid - 1;
    else if (q[mid] < Y)
      left = mid + 1;
  }
  return -1;
}

int main() {
  Int N, M;
  cin >> N >> M;
  vi P = vi(M);
  vi Y = vi(M);
  rep(i, M) {
    cin >> P[i];
    cin >> Y[i];
  }

  map<Int, vi> mp;
  rep(i, M) { mp[P[i]].push_back(Y[i]); }

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

  rep(i, M) {
    stringstream ans;
    Int yi = binary_search_index(Y[i], mp[P[i]]) + 1;
    ans << std::setw(6) << std::setfill('0') << P[i];
    ans << std::setw(6) << std::setfill('0') << yi;
    cout << ans.str() << endl;
  }

  return 0;
}
Problem p03221 (C++)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>

bool city(pair<P, int> a, pair<P, int> b) { return a.second < b.second; }

int main() {
  int n, m;
  cin >> n >> m;
  pair<P, int> c[n];
  rep(i, m) {
    cin >> c[i].first.first >> c[i].first.second;
    c[i].second = i;
  }
  sort(c, c + m);
  c[0].first.second = 1;

  rep(i, m - 1) {
    if (c[i + 1].first.first == c[i].first.first) {
      c[i + 1].first.second = c[i].first.second + 1;
    } else {
      c[i + 1].first.second = 1;
    }
  }
  sort(c, c + m, city);
  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << c[i].first.first;
    cout << setfill('0') << right << setw(6) << c[i].first.second << endl;
  }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>

bool city(pair<P, int> a, pair<P, int> b) { return a.second < b.second; }

int main() {
  int n, m;
  cin >> n >> m;
  pair<P, int> c[m];
  rep(i, m) {
    cin >> c[i].first.first >> c[i].first.second;
    c[i].second = i;
  }
  sort(c, c + m);
  c[0].first.second = 1;

  rep(i, m - 1) {
    if (c[i + 1].first.first == c[i].first.first) {
      c[i + 1].first.second = c[i].first.second + 1;
    } else {
      c[i + 1].first.second = 1;
    }
  }
  sort(c, c + m, city);
  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << c[i].first.first;
    cout << setfill('0') << right << setw(6) << c[i].first.second << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <set>
#include <string.h>
#include <vector>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> data(N + 1);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    data[P[i]].push_back(Y[i]);
  }
  for (int i = 0; i < N + 1; i++) {
    sort(data[i].begin(), data[i].end());
  }

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


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <set>
#include <string.h>
#include <vector>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<vector<int>> data(N + 1);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
    data[P[i]].push_back(Y[i]);
  }
  for (int i = 0; i < N + 1; i++) {
    sort(data[i].begin(), data[i].end());
  }

  for (int i = 0; i < M; i++) {
    vector<int> &d = data[P[i]];
    int k = lower_bound(d.begin(), d.end(), Y[i]) - d.begin();
    printf("%06d%06d\n", P[i], k + 1);
  }
}
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(i, 0, n)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp[n + 1];
  int p[n + 1], y[n + 1];

  REP(i, m) {
    cin >> p[i] >> y[i];
    mp[p[i]][y[i]]++;
  }

  FOR(i, 1, n + 1) {
    int cnt = 1;
    for (auto &x : mp[i]) {
      x.second = cnt++;
    }
  }

  REP(i, m) { printf("%06d%06d\n", p[i], mp[p[i]][y[i]]); }

  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(i, 0, n)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp[n + 1];
  int p[m + 1], y[m + 1];

  REP(i, m) {
    cin >> p[i] >> y[i];
    mp[p[i]][y[i]]++;
  }

  FOR(i, 1, n + 1) {
    int cnt = 1;
    for (auto &x : mp[i]) {
      x.second = cnt++;
    }
  }

  REP(i, m) { printf("%06d%06d\n", p[i], mp[p[i]][y[i]]); }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define all(L) L.begin(), L.end()
using ll = long long;
#define RO 1
#define SI 2
#define PA 3

int N, M;
int P[100000], Y[100000];
vector<int> idy[100001];

void dfs(int m, int bits, int &count) {
  if (m > N)
    return;
  if (bits == 0b111)
    count++;
  dfs(10 * m + 7, bits | 0b100, count);
  dfs(10 * m + 5, bits | 0b010, count);
  dfs(10 * m + 3, bits | 0b001, count);
}

int main() {
  cin >> N >> M;
  rep(i, 0, M) {
    cin >> P[i] >> Y[i];
    idy[P[i]].push_back(Y[i]);
  }
  rep(i, 0, M) { sort(idy[P[i]].begin(), idy[P[i]].end()); }

  rep(i, 0, M) {
    printf("%06d", P[i]);
    int x;
    x = (int)(lower_bound(idy[P[i]].begin(), idy[P[i]].end(), Y[i]) -
              idy[P[i]].begin()) +
        1;
    printf("%06d\n", x);
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define all(L) L.begin(), L.end()
using ll = long long;
#define RO 1
#define SI 2
#define PA 3

int N, M;
int P[100000], Y[100000];
vector<int> idy[100001];

void dfs(int m, int bits, int &count) {
  if (m > N)
    return;
  if (bits == 0b111)
    count++;
  dfs(10 * m + 7, bits | 0b100, count);
  dfs(10 * m + 5, bits | 0b010, count);
  dfs(10 * m + 3, bits | 0b001, count);
}

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

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


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

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> pys;
  vector<int> mp[N + 1];
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    pys.push_back(make_pair(p, y));
    mp[p].push_back(y);
  }

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

  for (auto &p : pys) {
    int pi = p.first;
    vector<int> v = mp[pi];
    auto iter = lower_bound(v.begin(), v.end(), p.second);
    int x = iter - v.begin() + 1;

    cout << setw(6) << setfill('0') << pi;
    cout << setw(6) << setfill('0') << x;
    cout << "\n";
  }

  return 0;
}

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

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

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> pys;
  vector<int> mp[N + 1];
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    pys.push_back(make_pair(p, y));
    mp[p].push_back(y);
  }

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

  for (auto &p : pys) {
    int pi = p.first;
    vector<int> &v = mp[pi];
    auto iter = lower_bound(v.begin(), v.end(), p.second);
    int x = iter - v.begin() + 1;

    cout << setw(6) << setfill('0') << pi;
    cout << setw(6) << setfill('0') << x;
    cout << "\n";
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int P[N + 1], Y[M + 1];
  vector<int> city[M + 1];
  REP(i, M) {
    cin >> P[i] >> Y[i];
    city[P[i]].push_back(Y[i]);
  }
  REP(i, N) sort(city[i + 1].begin(), city[i + 1].end());
  REP(i, M) {
    printf("%012lld\n",
           ll(P[i]) * 1000000 +
               int(lower_bound(ALL(city[P[i]]), Y[i]) - city[P[i]].begin()) +
               1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int P[100000], Y[100000];
  vector<int> city[100001];
  REP(i, M) {
    cin >> P[i] >> Y[i];
    city[P[i]].push_back(Y[i]);
  }
  REP(i, N) sort(city[i + 1].begin(), city[i + 1].end());
  REP(i, M) {
    printf("%012lld\n",
           ll(P[i]) * 1000000 +
               int(lower_bound(ALL(city[P[i]]), Y[i]) - city[P[i]].begin()) +
               1);
  }
}
Problem p03221 (C++)

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

using namespace std;

string buildString(int a, int b) {

  stringstream ss;
  stringstream ss2;

  ss << a;

  ss2 << b;

  string as = ss.str();

  for (int i = as.size(); i < 6; i++) {
    as = '0' + as;
  }

  string bs = ss2.str();

  for (int i = bs.size(); i < 6; i++) {
    bs = '0' + bs;
  }

  return as + bs;
}

int main() {

  int n, m;

  int x, y;

  cin >> n >> m;

  vector<pair<pair<int, int>, int>> container;

  for (int i = 0; i < m; i++) {

    cin >> x >> y;
    container.push_back(make_pair(make_pair(x, y), i));
  }

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

  int lastIndex = -1;
  int cont = 1;

  vector<string> ans(10005);
  string s;
  for (int i = 0; i < m; i++) {

    if (lastIndex == -1) {
      s = buildString(container[i].first.first, cont);
      ans[container[i].second] = s;
      lastIndex = container[i].first.first;
      continue;
    }

    if (lastIndex == container[i].first.first) {
      cont++;
      s = buildString(container[i].first.first, cont);
      ans[container[i].second] = s;

    } else {
      cont = 1;
      s = buildString(container[i].first.first, cont);
      ans[container[i].second] = s;
      lastIndex = container[i].first.first;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

using namespace std;

string buildString(int a, int b) {

  stringstream ss;
  stringstream ss2;

  ss << a;

  ss2 << b;

  string as = ss.str();

  for (int i = as.size(); i < 6; i++) {
    as = '0' + as;
  }

  string bs = ss2.str();

  for (int i = bs.size(); i < 6; i++) {
    bs = '0' + bs;
  }

  return as + bs;
}

int main() {

  int n, m;

  int x, y;

  cin >> n >> m;

  vector<pair<pair<int, int>, int>> container;

  for (int i = 0; i < m; i++) {

    cin >> x >> y;
    container.push_back(make_pair(make_pair(x, y), i));
  }

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

  int lastIndex = -1;
  int cont = 1;

  vector<string> ans(100005);
  string s;
  for (int i = 0; i < m; i++) {

    if (lastIndex == -1) {
      s = buildString(container[i].first.first, cont);
      ans[container[i].second] = s;
      lastIndex = container[i].first.first;
      continue;
    }

    if (lastIndex == container[i].first.first) {
      cont++;
      s = buildString(container[i].first.first, cont);
      ans[container[i].second] = s;

    } else {
      cont = 1;
      s = buildString(container[i].first.first, cont);
      ans[container[i].second] = s;
      lastIndex = container[i].first.first;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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;
}
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  map<int, vector<int>> mp;
  ll n, m;
  cin >> n >> m;
  vector<pair<int, int>> yp1, yp2;
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    yp1.emplace_back(y, p);
    yp2.emplace_back(y, p);
  }

  sort(ALL(yp1));
  for (auto &p : yp1) {
    mp[p.second].push_back(p.first);
  }

  for (auto &p : yp2) {
    auto v = mp[p.second];
    int num = int(lower_bound(ALL(v), p.first) - v.begin()) + 1;
    printf("%06d%06d\n", p.second, num);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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;
}
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  map<int, vector<int>> mp;
  ll n, m;
  cin >> n >> m;
  vector<pair<int, int>> yp1, yp2;
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    yp1.emplace_back(y, p);
    yp2.emplace_back(y, p);
  }

  sort(ALL(yp1));
  for (auto &p : yp1) {
    mp[p.second].push_back(p.first);
  }

  for (auto &p : yp2) {
    auto &v = mp[p.second];
    int num = int(lower_bound(ALL(v), p.first) - v.begin()) + 1;
    printf("%06d%06d\n", p.second, num);
  }

  return 0;
}
Problem p03221 (C++)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m), ansy(m);
  vector<pii> city[10010];

  for (int i = 0; i < m; i++) {
    cin >> p.at(i) >> y.at(i);
    city[p.at(i) - 1].push_back(pii(y.at(i), i));
  }

  for (int i = 0; i < n; i++) {
    sort(all(city[i]));

    for (int j = 0; j < city[i].size(); j++) {
      ansy.at(city[i].at(j).second) = j + 1;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << p.at(i);
    cout << setfill('0') << right << setw(6) << ansy.at(i) << endl;
  }

  return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m), ansy(m);
  vector<pii> city[100100];

  for (int i = 0; i < m; i++) {
    cin >> p.at(i) >> y.at(i);
    city[p.at(i) - 1].push_back(pii(y.at(i), i));
  }

  for (int i = 0; i < n; i++) {
    sort(all(city[i]));

    for (int j = 0; j < city[i].size(); j++) {
      ansy.at(city[i].at(j).second) = j + 1;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << p.at(i);
    cout << setfill('0') << right << setw(6) << ansy.at(i) << 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 all(x) (x).begin(), (x).end()
static const int INF(1 << 30);

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

  vector<tuple<int, int, int>> city;
  vector<pair<int, int>> ans(N);
  rep(i, M) {
    int p, y;
    cin >> p >> y;
    city.push_back(make_tuple(p, y, i));
  }

  sort(all(city));

  int pref_prev = get<0>(city[0]);
  // int pref_prev = city[0].first;
  int cnt_city = 0;
  rep(i, M) {
    int pref_now = get<0>(city[i]);
    // int pref_now = city[i].first;
    if (pref_now == pref_prev) {
      cnt_city++;
    } else {
      cnt_city = 1;
      pref_prev = pref_now;
    }

    // printf("%06d%06d\n", pref_now, cnt_city);
    int idx = get<2>(city[i]);
    ans[idx] = make_pair(pref_now, cnt_city);
  }

  rep(i, M) { printf("%06d%06d\n", ans[i].first, ans[i].second); }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF(1 << 30);

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

  vector<tuple<int, int, int>> city;
  vector<pair<int, int>> ans(M);
  rep(i, M) {
    int p, y;
    cin >> p >> y;
    city.push_back(make_tuple(p, y, i));
  }

  sort(all(city));

  int pref_prev = get<0>(city[0]);
  // int pref_prev = city[0].first;
  int cnt_city = 0;
  rep(i, M) {
    int pref_now = get<0>(city[i]);
    // int pref_now = city[i].first;
    if (pref_now == pref_prev) {
      cnt_city++;
    } else {
      cnt_city = 1;
      pref_prev = pref_now;
    }

    // printf("%06d%06d\n", pref_now, cnt_city);
    int idx = get<2>(city[i]);
    ans[idx] = make_pair(pref_now, cnt_city);
  }

  rep(i, M) { printf("%06d%06d\n", ans[i].first, ans[i].second); }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);
int n, m;
int p[100000];
ll y[100000];
vector<ll> yd[100001];

int main(void) {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }

  for (int i = 0; i < m; i++) {
    sort(yd[p[i]].begin(), yd[p[i]].end());
  }

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);
int n, m;
int p[100000];
ll y[100000];
vector<ll> yd[100001];

int main(void) {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }

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

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

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, mm;
  cin >> n >> mm;
  vector<vector<ll>> m(n);
  vector<pair<int, ll>> v(mm);
  for (int i = 0; i < mm; i++) {
    cin >> v[i].first >> v[i].second;
    m[v[i].first - 1].push_back(v[i].second);
  }
  for (int i = 0; i < n; i++)
    sort(m[i].begin(), m[i].end());
  for (int i = 0; i < mm; i++) {
    int a = v[i].first;
    ll b = v[i].second;
    int x = find(m[a - 1].begin(), m[a - 1].end(), b) - m[a - 1].begin() + 1;
    printf("%06d", a);
    printf("%06d", x);
    cout << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, mm;
  cin >> n >> mm;
  vector<vector<ll>> m(n);
  vector<pair<int, ll>> v(mm);
  for (int i = 0; i < mm; i++) {
    cin >> v[i].first >> v[i].second;
    m[v[i].first - 1].push_back(v[i].second);
  }
  for (int i = 0; i < n; i++)
    sort(m[i].begin(), m[i].end());
  for (int i = 0; i < mm; i++) {
    int a = v[i].first;
    ll b = v[i].second;
    int x =
        lower_bound(m[a - 1].begin(), m[a - 1].end(), b) - m[a - 1].begin() + 1;
    printf("%06d", a);
    printf("%06d", x);
    cout << endl;
  }
}
Problem p03221 (C++)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  REP(i, M)
  cin >> P[i] >> Y[i];
  vector<int> vc[100001];
  REP(i, M)
  vc[P[i]].push_back(Y[i]);
  REP(i, M)
  sort(ALL(vc[P[i]]));
  REP(i, M)
  printf("%06d%06d\n", P[i],
         lower_bound(ALL(vc[P[i]]), Y[i]) - vc[P[i]].begin() + 1);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  REP(i, M)
  cin >> P[i] >> Y[i];
  vector<int> vc[100001];
  REP(i, M)
  vc[P[i]].push_back(Y[i]);
  REP1(i, N)
  sort(ALL(vc[i]));
  REP(i, M)
  printf("%06d%06d\n", P[i],
         lower_bound(ALL(vc[P[i]]), Y[i]) - vc[P[i]].begin() + 1);
  return 0;
}
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;
  int P[M], Y[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
  }
  vector<int> vec[100001];
  for (int i = 0; i < M; i++) {
    vec[P[i]].push_back(Y[i]);
  }
  for (int i = 1; i <= N; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", P[i],
           distance(vec[P[i]].begin(),
                    find(vec[P[i]].begin(), vec[P[i]].end(), Y[i])) +
               1);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int P[M], Y[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> Y[i];
  }
  vector<int> vec[100001];
  for (int i = 0; i < M; i++) {
    vec[P[i]].push_back(Y[i]);
  }
  for (int i = 1; i <= N; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", P[i],
           lower_bound(vec[P[i]].begin(), vec[P[i]].end(), Y[i]) -
               vec[P[i]].begin() + 1);
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P;
  vector<ll> Y;
  vector<ll> PY[N + 1];
  rep(i, M) {
    int p;
    ll y;
    cin >> p >> y;
    P.push_back(p);
    Y.push_back(y);
    PY[p].push_back(y);
  }
  rep(i, M) {
    int p = P[i];
    sort(PY[p].begin(), PY[p].end());
  }

  rep(i, M) {
    auto iter = lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]);

    string birthnum = to_string(1 + iter - PY[P[i]].begin());
    string barthzero = string(6 - birthnum.size(), '0');
    string recnum = to_string(P[i]);
    string reczero = string(6 - recnum.size(), '0');

    string ans = reczero + recnum + barthzero + birthnum;
    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P;
  vector<ll> Y;
  vector<ll> PY[N + 1];
  rep(i, M) {
    int p;
    ll y;
    cin >> p >> y;
    P.push_back(p);
    Y.push_back(y);
    PY[p].push_back(y);
  }
  for (int i = 1; i <= N; i++) {
    sort(PY[i].begin(), PY[i].end());
  }

  rep(i, M) {
    auto iter = lower_bound(PY[P[i]].begin(), PY[P[i]].end(), Y[i]);

    string birthnum = to_string(1 + iter - PY[P[i]].begin());
    string barthzero = string(6 - birthnum.size(), '0');
    string recnum = to_string(P[i]);
    string reczero = string(6 - recnum.size(), '0');

    string ans = reczero + recnum + barthzero + birthnum;
    cout << ans << endl;
  }
}
Problem p03221 (C++)

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

struct city {
  int pref;
  int year;
};

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

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

  map<int, vector<int>> table;
  for (int i = 0; i < m; i++) {
    if (table.count(v[i].pref)) {
      table[v[i].pref].push_back(v[i].year);
    } else {
      vector<int> tmp = {v[i].year};
      table[v[i].pref] = tmp;
    }
  }

  for (auto it = table.begin(); it != table.end(); it++) {
    sort((it->second).begin(), (it->second).end());
  }

  for (int i = 0; i < m; i++) {
    auto it = find(table[v[i].pref].begin(), table[v[i].pref].end(), v[i].year);
    int index = distance(table[v[i].pref].begin(), it);

    cout << setfill('0') << right << setw(6) << v[i].pref;
    cout << setfill('0') << right << setw(6) << index + 1 << endl;
  }
}

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

struct city {
  int pref;
  int year;
};

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

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

  map<int, vector<int>> table;
  for (int i = 0; i < m; i++) {
    if (table.count(v[i].pref)) {
      table[v[i].pref].push_back(v[i].year);
    } else {
      vector<int> tmp = {v[i].year};
      table[v[i].pref] = tmp;
    }
  }

  for (auto it = table.begin(); it != table.end(); it++) {
    sort((it->second).begin(), (it->second).end());
  }

  for (int i = 0; i < m; i++) {
    auto it = lower_bound(table[v[i].pref].begin(), table[v[i].pref].end(),
                          v[i].year);
    int index = distance(table[v[i].pref].begin(), it);

    cout << setfill('0') << right << setw(6) << v[i].pref;
    cout << setfill('0') << right << setw(6) << index + 1 << endl;
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m;
  vector<int> c(n), d(n);
  vector<vector<int>> e(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
    e[c[i]].push_back(d[i]);
  }
  for (int i = 0; i < n + 1; i++) {
    sort(e[i].begin(), e[i].end());
  }
  for (int i = 0; i < m; i++) {
    x = lower_bound(e[c[i]].begin(), e[c[i]].end(), d[i]) - e[c[i]].begin() + 1;
    printf("%06d", c[i]);
    printf("%06d\n", x);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m;
  vector<int> c(m), d(m);
  vector<vector<int>> e(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
    e[c[i]].push_back(d[i]);
  }
  for (int i = 0; i < n + 1; i++) {
    sort(e[i].begin(), e[i].end());
  }
  for (int i = 0; i < m; i++) {
    x = lower_bound(e[c[i]].begin(), e[c[i]].end(), d[i]) - e[c[i]].begin() + 1;
    printf("%06d", c[i]);
    printf("%06d\n", x);
  }
}