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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, a) repi(i, 0, a)
#define all(u) u.begin(), u.end()
#define pl pair<ll, ll>
#define fi first
#define se second
#define inf 1000000007

ll N, M;
vector<pl> city;
vector<ll> Data[100010];

ll keta(ll n) {
  ll res = 0;
  while (n / 10 != 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main() {
  scanf("%lld%lld", &N, &M);
  rep(i, M) {
    ll P, Y;
    scanf("%lld%lld", &P, &Y);
    pl temp;
    temp.fi = P;
    temp.se = Y;
    city.push_back(temp);
    Data[P].push_back(Y);
  }
  rep(i, 100010) {
    if (Data[i].size() != 0) {
      sort(Data[i].begin(), Data[i].end());
    }
  }
  rep(i, M) {
    ll x;
    ll f = city[i].fi;
    ll s = city[i].se;
    rep(j, Data[f].size()) {
      if (Data[f][j] == s) {
        x = j + 1;
        break;
      }
    }
    string str;
    string strr;
    ll k = keta(f);
    ll K = keta(x);
    rep(j, 6 - k - 1) str += "0";
    rep(j, 6 - K - 1) strr += "0";
    cout << str << city[i].fi << strr << x << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, a) repi(i, 0, a)
#define all(u) u.begin(), u.end()
#define pl pair<ll, ll>
#define fi first
#define se second
#define inf 1000000007

ll N, M;
vector<pl> city;
vector<ll> Data[100010];

ll keta(ll n) {
  ll res = 0;
  while (n / 10 != 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main() {
  scanf("%lld%lld", &N, &M);
  rep(i, M) {
    ll P, Y;
    scanf("%lld%lld", &P, &Y);
    pl temp;
    temp.fi = P;
    temp.se = Y;
    city.push_back(temp);
    Data[P].push_back(Y);
  }
  rep(i, 100010) {
    if (Data[i].size() != 0) {
      sort(Data[i].begin(), Data[i].end());
    }
  }
  rep(i, M) {
    ll x;
    ll f = city[i].fi;
    ll s = city[i].se;
    x = lower_bound(Data[f].begin(), Data[f].end(), s) - Data[f].begin() + 1;
    string str;
    string strr;
    ll k = keta(f);
    ll K = keta(x);
    rep(j, 6 - k - 1) str += "0";
    rep(j, 6 - K - 1) strr += "0";
    cout << str << city[i].fi << strr << x << endl;
  }
  return 0;
}
Problem p03221 (C++)

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<pint, int>> data(M);
  vector<string> ans(M);
  REP(i, M) {
    int p, y;
    cin >> p >> y;
    data[i] = make_pair(make_pair(p, y), i);
  }
  sort(data.begin(), data.end());
  int num = 0;
  REP(i, M) {
    if (i == 0 || data[i].first.first != data[i - 1].first.first) {
      num = 1;
    } else {
      num++;
    }
    static char id[10];
    sprintf(id, "%06d%06d", data[i].first.first, num);
    ans[data[i].second] = string(id);
  }
  REP(i, M) { cout << ans[i] << endl; }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<pint, int>> data(M);
  vector<string> ans(M);
  REP(i, M) {
    int p, y;
    cin >> p >> y;
    data[i] = make_pair(make_pair(p, y), i);
  }
  sort(data.begin(), data.end());
  int num = 0;
  REP(i, M) {
    if (i == 0 || data[i].first.first != data[i - 1].first.first) {
      num = 1;
    } else {
      num++;
    }
    static char id[100];
    sprintf(id, "%06d%06d", data[i].first.first, num);
    ans[data[i].second] = string(id);
  }
  REP(i, M) { cout << ans[i] << endl; }

  return 0;
}
Problem p03221 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[p[i + 1]].begin(), yd[p[i + 1]].end());
  rep(i, m) printf("%06lld", p[i]),
      printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                             yd[p[i]].begin() + 1LL);
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%06lld", p[i]),
      printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                             yd[p[i]].begin() + 1LL);
}
Problem p03221 (C++)

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> hoge(m);
  map<int, vector<int>> fuga;

  for (int i = 0; i < m; i++) {
    cin >> hoge.at(i).first >> hoge.at(i).second;
    fuga[hoge.at(i).first].push_back(hoge.at(i).second);
  }

  for (auto a : hoge) {
    sort(fuga[a.first].begin(), fuga[a.first].end());
  }

  for (auto at : hoge) {
    int a = at.first;
    int b = at.second;

    int fst = a;
    int ed = 0;

    int left = 0;
    int right = fuga[a].size() - 1;

    while (left <= right) {
      int mid = (left + right) / 2;

      if (fuga[a].at(mid) == b) {
        ed = mid + 1;
        break;
      } else if (fuga[a].at(mid) > b) {
        right = mid - 1;
      } else {
        left = mid + 1;
      }
    }

    string mae = to_string(fst);
    string usiro = to_string(ed);

    while (mae.size() < 6) {
      mae = "0" + mae;
    }

    while (usiro.size() < 6) {
      usiro = "0" + usiro;
    }

    cout << mae + usiro << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> hoge(m);
  map<int, vector<int>> fuga;

  for (int i = 0; i < m; i++) {
    cin >> hoge.at(i).first >> hoge.at(i).second;
    fuga[hoge.at(i).first].push_back(hoge.at(i).second);
  }

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

  for (auto at : hoge) {
    int a = at.first;
    int b = at.second;

    int fst = a;
    int ed = 0;

    int left = 0;
    int right = fuga[a].size() - 1;

    while (left <= right) {
      int mid = (left + right) / 2;

      if (fuga[a].at(mid) == b) {
        ed = mid + 1;
        break;
      } else if (fuga[a].at(mid) > b) {
        right = mid - 1;
      } else {
        left = mid + 1;
      }
    }

    string mae = to_string(fst);
    string usiro = to_string(ed);

    while (mae.size() < 6) {
      mae = "0" + mae;
    }

    while (usiro.size() < 6) {
      usiro = "0" + usiro;
    }

    cout << mae + usiro << endl;
  }

  return 0;
}
Problem p03221 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(100010, vector<int>());
  vector<P> ve(m);
  rep(i, m) {
    int p, y;
    scanf("%d%d", &p, &y);
    ve[i].first = p;
    ve[i].second = y;
    vec[p].push_back(y);
  }
  rep(i, 100010) sort(vec[i].begin(), vec[i].end());
  rep(i, m) {
    int e;
    rep(j, vec[ve[i].first].size()) {
      if (vec[ve[i].first][j] == ve[i].second) {
        e = j;
        break;
      }
    }
    printf("%06d", ve[i].first);
    printf("%06d\n", e + 1);
  }
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(100010, vector<int>());
  vector<P> ve(m);
  rep(i, m) {
    int p, y;
    scanf("%d%d", &p, &y);
    ve[i].first = p;
    ve[i].second = y;
    vec[p].push_back(y);
  }
  rep(i, 100010) sort(vec[i].begin(), vec[i].end());
  rep(i, m) printf("%012lld\n",
                   ll(ve[i].first) * 1000000 +
                       int(lower_bound(vec[ve[i].first].begin(),
                                       vec[ve[i].first].end(), ve[i].second) -
                           vec[ve[i].first].begin()) +
                       1);
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

struct city {
  Int pref; // 県番号
  Int year;
  Int num; // 県の内何番目か
  Int id;  // 入力番号
};

int main() {

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

  Int N, M;
  cin >> N >> M;

  vector<city> cities(M);
  for (Int i = 0; i < M; i++) {
    cin >> cities[i].pref >> cities[i].year;
    cities[i].id = i;
  }

  // yearでsort
  sort(cities.begin(), cities.end(),
       [](const city &x, const city &y) { return x.year < y.year; });

  vector<Int> Pre(M + 1);
  for (Int i = 0; i < M; i++) {
    Pre[cities[i].pref]++;
    cities[i].num = Pre[cities[i].pref];
  }

  // idでsort
  sort(cities.begin(), cities.end(),
       [](const city &x, const city &y) { return x.id < y.id; });

  for (Int i = 0; i < M; i++) {
    printf("%06lld", cities[i].pref);
    printf("%06lld\n", cities[i].num);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

struct city {
  Int pref; // 県番号
  Int year;
  Int num; // 県の内何番目か
  Int id;  // 入力番号
};

int main() {

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

  Int N, M;
  cin >> N >> M;

  vector<city> cities(M);
  for (Int i = 0; i < M; i++) {
    cin >> cities[i].pref >> cities[i].year;
    cities[i].id = i;
  }

  // yearでsort
  sort(cities.begin(), cities.end(),
       [](const city &x, const city &y) { return x.year < y.year; });

  vector<Int> Pre(100001);
  for (Int i = 0; i < M; i++) {
    Pre[cities[i].pref]++;
    cities[i].num = Pre[cities[i].pref];
  }

  // idでsort
  sort(cities.begin(), cities.end(),
       [](const city &x, const city &y) { return x.id < y.id; });

  for (Int i = 0; i < M; i++) {
    printf("%06lld", cities[i].pref);
    printf("%06lld\n", cities[i].num);
  }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> order[n];
  vector<pair<int, int>> city(m);
  for (int i = 0; i < m; i++) {
    cin >> city[i].first >> city[i].second;
    order[city[i].first - 1].push_back(city[i].second);
  }
  for (int i = 0; i < n; i++) {
    sort(order[i].begin(), order[i].end());
  }

  for (int i = 0; i < m; i++) {
    int prefercture = city[i].first - 1;
    int birth;
    for (int j = 0; j < order[prefercture].size(); ++j) {
      if (order[prefercture][j] == city[i].second) {
        birth = j + 1;
        break;
      }
    }
    printf("%06d%06d\n", prefercture + 1, birth);
    // cout << prefercture+1 << " " << birth << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> order[n];
  vector<pair<int, int>> city(m);
  for (int i = 0; i < m; i++) {
    cin >> city[i].first >> city[i].second;
    order[city[i].first - 1].push_back(city[i].second);
  }
  for (int i = 0; i < n; i++) {
    sort(order[i].begin(), order[i].end());
  }

  for (int i = 0; i < m; i++) {
    int prefercture = city[i].first - 1;
    auto birthIter = lower_bound(order[prefercture].begin(),
                                 order[prefercture].end(), city[i].second);
    int birth = birthIter - order[prefercture].begin() + 1;
    printf("%06d%06d\n", prefercture + 1, birth);
    // cout << prefercture+1 << " " << birth << endl;
  }
  return 0;
}
Problem p03221 (C++)

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

using namespace std;

#define sp(x) cout << setprecision(x);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m; // n=prefecture m=city
  vector<vector<P>> v(m);
  REP(i, m) {
    int p, y; //
    cin >> p >> y;
    P temp;
    p--;
    temp.first = y;
    temp.second = i;
    v[p].push_back(temp);
    // v[i].push_back(P(p,y));
  }
  vector<P> ans(m);

  REP(i, n) {
    sort(all(v[i]));
    // v[i][j] := i個目の県の中でｊ番目に速く誕生した市の誕生した年と市の番号
    REP(j, v[i].size()) { ans[v[i][j].second] = P(i + 1, j + 1); }
  }

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

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

using namespace std;

#define sp(x) cout << setprecision(x);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m; // n=prefecture m=city
  vector<vector<P>> v(n);
  REP(i, m) {
    int p, y; //
    cin >> p >> y;
    P temp;
    p--;
    temp.first = y;
    temp.second = i;
    v[p].push_back(temp);
    // v[i].push_back(P(p,y));
  }
  vector<P> ans(m);

  REP(i, n) {
    sort(all(v[i]));
    // v[i][j] := i個目の県の中でｊ番目に速く誕生した市の誕生した年と市の番号
    REP(j, v[i].size()) { ans[v[i][j].second] = P(i + 1, j + 1); }
  }

  REP(i, m) { printf("%06d%06d\n", ans[i].first, ans[i].second); }
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main() {

  long N, M;
  vector<vector<long long>> P;

  cin >> N >> M;

  P = vector<vector<long long>>(N, vector<long long>(0, 0));
  long long p[M], y[M];

  for (long i = 0; i < M; i++) {
    scanf("%lld %lld", &p[i], &y[i]);
    P[--p[i]].push_back(y[i]);
  }

  for (long i = 0; i < N; i++) {
    if (P[i].size() != 0)
      sort(P[i].begin(), P[i].end());
  }

  for (long i = 0; i < M; i++) {
    auto itr = find(P[p[i]].begin(), P[p[i]].end(), y[i]);
    long idx = distance(P[p[i]].begin(), itr);
    printf("%06lld%06ld\n", p[i] + 1, idx + 1);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main() {

  long N, M;
  vector<vector<long long>> P;

  cin >> N >> M;

  P = vector<vector<long long>>(N, vector<long long>(0, 0));
  long long p[M], y[M];

  for (long i = 0; i < M; i++) {
    scanf("%lld %lld", &p[i], &y[i]);
    P[--p[i]].push_back(y[i]);
  }

  for (long i = 0; i < N; i++) {
    if (P[i].size() != 0)
      sort(P[i].begin(), P[i].end());
  }

  for (long i = 0; i < M; i++) {
    auto itr = lower_bound(P[p[i]].begin(), P[p[i]].end(), y[i]);
    long idx = distance(P[p[i]].begin(), itr);
    printf("%06lld%06ld\n", p[i] + 1, idx + 1);
  }

  return 0;
}
Problem p03221 (C++)

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

int inum(int N, int W) { return N / W; }
int jnum(int N, int W) {
  if ((N / W) % 2)
    return N % W;
  else
    return W - (N % W) - 1;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> P(n), Y(n);
  vector<vector<int>> yd(n + 1);
  rep(i, m) {
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }

  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) cout << setw(12) << setfill('0')
                 << ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(),
                                                         yd[P[i]].end(), Y[i]) -
                                             yd[P[i]].begin() + 1)
                 << endl;
}


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

int inum(int N, int W) { return N / W; }
int jnum(int N, int W) {
  if ((N / W) % 2)
    return N % W;
  else
    return W - (N % W) - 1;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> P(m), Y(m);
  vector<vector<int>> yd(n + 1);
  rep(i, m) {
    cin >> P[i] >> Y[i];
    yd[P[i]].push_back(Y[i]);
  }

  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) cout << setw(12) << setfill('0')
                 << ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(),
                                                         yd[P[i]].end(), Y[i]) -
                                             yd[P[i]].begin() + 1)
                 << endl;
}
Problem p03221 (C++)

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

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  vector<tuple<int, int, int>> pref_year_id(M);
  for (int i = 0; i < M; i++) {
    int pid, year;
    scanf("%d%d", &pid, &year);
    pref_year_id.at(i) = make_tuple(pid, year, i);
  }

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

  vector<int> pref_id(M), city_id(M), cnt(M + 1);
  for (auto pyi : pref_year_id) {
    int pid, id;
    tie(pid, ignore, id) = pyi;
    pref_id.at(id) = pid;
    cnt[pid]++;
    city_id.at(id) = cnt[pid];
  }

  for (int i = 0; i < M; i++) {
    cout << setfill('0') << setw(6) << pref_id.at(i);
    cout << setfill('0') << setw(6) << city_id.at(i) << endl;
  }
  return 0;
}


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

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  vector<tuple<int, int, int>> pref_year_id(M);
  for (int i = 0; i < M; i++) {
    int pid, year;
    scanf("%d%d", &pid, &year);
    pref_year_id.at(i) = make_tuple(pid, year, i);
  }

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

  vector<int> pref_id(M), city_id(M), cnt(N + 1);
  for (auto &pyi : pref_year_id) {
    int pid, id;
    tie(pid, ignore, id) = pyi;
    pref_id.at(id) = pid;
    cnt[pid]++;
    city_id.at(id) = cnt[pid];
  }

  for (int i = 0; i < M; i++) {
    cout << setfill('0') << setw(6) << pref_id.at(i);
    cout << setfill('0') << setw(6) << city_id.at(i) << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct city {
  int id1;
  int id2;
  int year;
  int num;
};
city cities[10002];
bool cmp1(city a, city b) {
  if (a.id1 != b.id1) {
    return a.id1 < b.id1;
  } else {
    return a.year < b.year;
  }
}
bool cmp2(city a, city b) { return a.num < b.num; }
void add0(int a) {
  if (a < 10) {
    cout << "00000";
  } else if (a < 100) {
    cout << "0000";
  } else if (a < 1000) {
    cout << "000";
  } else if (a < 10000) {
    cout << "00";
  } else if (a < 100000) {
    cout << "0";
  }
  cout << a;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> cities[i].id1 >> cities[i].year;
    cities[i].num = i;
  }
  sort(cities, cities + m, cmp1);
  int t1 = 0;
  cities[0].id2 = 1;
  for (int i = 1; i < m; i++) {
    if (cities[i].id1 != cities[i - 1].id1) {
      cities[i].id2 = 1;
    } else {
      cities[i].id2 = cities[i - 1].id2 + 1;
    }
  }
  sort(cities, cities + m, cmp2);
  for (int i = 0; i < m; i++) {
    add0(cities[i].id1);
    add0(cities[i].id2);
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct city {
  int id1;
  int id2;
  int year;
  int num;
};
city cities[100002];
bool cmp1(city a, city b) {
  if (a.id1 != b.id1) {
    return a.id1 < b.id1;
  } else {
    return a.year < b.year;
  }
}
bool cmp2(city a, city b) { return a.num < b.num; }
void add0(int a) {
  if (a < 10) {
    cout << "00000";
  } else if (a < 100) {
    cout << "0000";
  } else if (a < 1000) {
    cout << "000";
  } else if (a < 10000) {
    cout << "00";
  } else if (a < 100000) {
    cout << "0";
  }
  cout << a;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> cities[i].id1 >> cities[i].year;
    cities[i].num = i;
  }
  sort(cities, cities + m, cmp1);
  int t1 = 0;
  cities[0].id2 = 1;
  for (int i = 1; i < m; i++) {
    if (cities[i].id1 != cities[i - 1].id1) {
      cities[i].id2 = 1;
    } else {
      cities[i].id2 = cities[i - 1].id2 + 1;
    }
  }
  sort(cities, cities + m, cmp2);
  for (int i = 0; i < m; i++) {
    add0(cities[i].id1);
    add0(cities[i].id2);
    cout << endl;
  }
  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
int main(void) {
  int n, m;
  scanf("%lld%lld", &n, &m);
  unsigned long long p[m], y[m];
  unsigned long long x[m];
  for (int i = 0; i < m; i++) {
    scanf("%lu%lu", &p[i], &y[i]);
    x[i] = (p[i] << 47) + (y[i] << 17) + i;
  }
  std::sort(x, x + m);
  int c = 1;
  y[(x[0] << 47) >> 47] = c;
  for (int i = 1; i < m; i++) {
    if (x[i] >> 47 == x[i - 1] >> 47)
      c++;
    else
      c = 1;
    y[(x[i] << 47) >> 47] = c;
  }
  for (int i = 0; i < m; i++) {
    printf("%06lu%06lu\n", p[i], y[i]);
  }
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  unsigned long long p[m], y[m];
  unsigned long long x[m];
  for (int i = 0; i < m; i++) {
    scanf("%lu%lu", &p[i], &y[i]);
    x[i] = (p[i] << 47) + (y[i] << 17) + i;
  }
  std::sort(x, x + m);
  int c = 1;
  y[(x[0] << 47) >> 47] = c;
  for (int i = 1; i < m; i++) {
    if (x[i] >> 47 == x[i - 1] >> 47)
      c++;
    else
      c = 1;
    y[(x[i] << 47) >> 47] = c;
  }
  for (int i = 0; i < m; i++) {
    printf("%06lu%06lu\n", p[i], y[i]);
  }
}
Problem p03221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

// #define INF 100000000
// #define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int MAX = 1000000;
const int MOD = 998244353;

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

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

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

  for (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 (i = 0; i < m; i++) {
    printf("%06d", p[i] + 1);

    // 座圧との対応付け
    int id =
        lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
    printf("%06d\n", id + 1);
  }
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

// #define INF 100000000
// #define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int MAX = 1000000;
const int MOD = 998244353;

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

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

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

  for (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 (i = 0; i < m; i++) {
    printf("%06d", p[i] + 1);

    // 座圧との対応付け
    int id =
        lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin();
    printf("%06d\n", id + 1);
  }
}
Problem p03221 (C++)

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

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

  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    P--;
    p.at(i) = make_pair(Y, P);
  }

  vector<vector<int>> vals(N);
  for (int i = 0; i < M; i++)
    vals.at(p.at(i).second).push_back(p.at(i).first);

  for (int v = 0; v < N; v++) {
    sort(vals.at(v).begin(), vals.at(v).end());
  }

  for (int i = 0; i < M; ++i) {
    int v = p.at(i).second;
    printf("%06d", v + 1);
    int id = lower_bound(vals.at(v).begin(), vals.at(v).end(), p.at(v).first) -
             vals.at(v).begin();
    printf("%06d\n", id + 1);
  }
}

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

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

  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    P--;
    p.at(i) = make_pair(Y, P);
  }

  vector<vector<int>> vals(N);
  for (int i = 0; i < M; i++)
    vals.at(p.at(i).second).push_back(p.at(i).first);

  for (int v = 0; v < N; v++) {
    sort(vals.at(v).begin(), vals.at(v).end());
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
struct city {
  int p;
  int y;
  int bian1;
  int bian2;
} c[10005];
bool cmp1(city a, city b) {
  if (a.p != b.p) {
    return a.p < b.p;
  } else {
    return a.y < b.y;
  }
}
bool cmp2(city a, city b) { return a.bian1 < b.bian1; }
int main() {
  int n, m, i, x, s = 0, j = 0, z, t = 0, k;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> c[i].p >> c[i].y;
    c[i].bian1 = i;
  }
  sort(c + 1, c + m + 1, cmp1);
  int y = c[1].p;
  for (i = 1; i <= m; i++) {
    if (c[i].p == y) {
      j++;
      c[i].bian2 = j;
    } else {
      j = 1;
      y = c[i].p;
      c[i].bian2 = j;
    }
  }
  sort(c + 1, c + m + 1, cmp2);
  /*
  ////////////begin
  for(i=1;i<=m;i++)
  {
          cout<<c[i].p<<' '<<c[i].y<<' '<<c[i].bian1<<' '<<c[i].bian2<<endl;
  }
  ////////////end
  */
  for (i = 1; i <= m; i++) {
    x = c[i].p;
    while (x != 0) {
      x = x / 10;
      s++;
    }
    for (k = 1; k <= 6 - s; k++) {
      cout << '0';
    }
    cout << c[i].p;
    s = 0;
    z = c[i].bian2;
    while (z != 0) {
      z = z / 10;
      t++;
    }
    for (k = 1; k <= 6 - t; k++) {
      cout << '0';
    }
    cout << c[i].bian2 << endl;
    t = 0;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
struct city {
  int p;
  int y;
  int bian1;
  int bian2;
} c[100005];
bool cmp1(city a, city b) {
  if (a.p != b.p) {
    return a.p < b.p;
  } else {
    return a.y < b.y;
  }
}
bool cmp2(city a, city b) { return a.bian1 < b.bian1; }
int main() {
  int n, m, i, x, s = 0, j = 0, z, t = 0, k;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> c[i].p >> c[i].y;
    c[i].bian1 = i;
  }
  sort(c + 1, c + m + 1, cmp1);
  int y = c[1].p;
  for (i = 1; i <= m; i++) {
    if (c[i].p == y) {
      j++;
      c[i].bian2 = j;
    } else {
      j = 1;
      y = c[i].p;
      c[i].bian2 = j;
    }
  }
  sort(c + 1, c + m + 1, cmp2);
  /*
  ////////////begin
  for(i=1;i<=m;i++)
  {
          cout<<c[i].p<<' '<<c[i].y<<' '<<c[i].bian1<<' '<<c[i].bian2<<endl;
  }
  ////////////end
  */
  for (i = 1; i <= m; i++) {
    x = c[i].p;
    while (x != 0) {
      x = x / 10;
      s++;
    }
    for (k = 1; k <= 6 - s; k++) {
      cout << '0';
    }
    cout << c[i].p;
    s = 0;
    z = c[i].bian2;
    while (z != 0) {
      z = z / 10;
      t++;
    }
    for (k = 1; k <= 6 - t; k++) {
      cout << '0';
    }
    cout << c[i].bian2 << endl;
    t = 0;
  }
  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<int> p(m);
  vector<int> y(m);
  vector<int> py[100001];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    py[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < m; i++) {
    sort(py[p[i]].begin(), py[p[i]].end());
  }
  for (int i = 0; i < m; i++) {
    printf("%06d%06d\n", p[i],
           (lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i])) -
               py[p[i]].begin() + 1);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<int> y(m);
  vector<int> py[100001];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    py[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n; i++) {
    sort(py[i + 1].begin(), py[i + 1].end());
  }
  for (int i = 0; i < m; i++) {
    printf("%06d%06d\n", p[i],
           (lower_bound(py[p[i]].begin(), py[p[i]].end(), y[i])) -
               py[p[i]].begin() + 1);
  }
  return 0;
}
Problem p03221 (C++)

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

int answer[100005], preI[100005];

int main() {
  int n, m, an, pr;
  cin >> n >> m;
  pair<int, pair<int, int>> v[n + 10];
  for (int i = 0; i < m; i++) {
    cin >> pr >> an;
    v[i].second.first = an;
    v[i].first = pr;
    v[i].second.second = i;
  }
  sort(v, v + m);

  int indx = 1;
  for (int i = 0; i < m; i++) {
    if (i > 0 && v[i].first != v[i - 1].first) {
      indx = 1;
    }
    answer[v[i].second.second] = indx;
    preI[v[i].second.second] = v[i].first;
    indx++;
  }
  for (int i = 0; i < m; i++) {
    printf("%06d", preI[i]);
    printf("%06d\n", answer[i]);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;

int answer[100005], preI[100005];

int main() {
  int n, m, an, pr;
  cin >> n >> m;
  pair<int, pair<int, int>> v[m + 10];
  for (int i = 0; i < m; i++) {
    cin >> pr >> an;
    v[i].second.first = an;
    v[i].first = pr;
    v[i].second.second = i;
  }
  sort(v, v + m);

  int indx = 1;
  for (int i = 0; i < m; i++) {
    if (i > 0 && v[i].first != v[i - 1].first) {
      indx = 1;
    }
    answer[v[i].second.second] = indx;
    preI[v[i].second.second] = v[i].first;
    indx++;
  }
  for (int i = 0; i < m; i++) {
    printf("%06d", preI[i]);
    printf("%06d\n", answer[i]);
  }

  return 0;
}
Problem p03221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _                                                                      \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
llong n, m;
llong y[100010], p[100010];
V yp[100010];

int main() {
  _;
  cin >> n >> m;
  REP(i, m) {
    llong yy, pp;
    cin >> pp >> yy;
    y[i] = yy;
    p[i] = pp;
    yp[pp - 1].push_back(yy);
  }

  REP(i, m) VSORT(yp[p[i] - 1]);

  REP(i, m) {
    int index = lower_bound(yp[p[i] - 1].begin(), yp[p[i] - 1].end(), y[i]) -
                yp[p[i] - 1].begin() + 1;
    printf("%06lld%06d\n", p[i], index);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _                                                                      \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
llong n, m;
llong y[100010], p[100010];
V yp[100010];

int main() {
  _;
  cin >> n >> m;
  REP(i, m) {
    llong yy, pp;
    cin >> pp >> yy;
    y[i] = yy;
    p[i] = pp;
    yp[pp - 1].push_back(yy);
  }

  REP(i, n) VSORT(yp[i]);
  REP(i, m) {
    int index = lower_bound(yp[p[i] - 1].begin(), yp[p[i] - 1].end(), y[i]) -
                yp[p[i] - 1].begin() + 1;
    printf("%06lld%06d\n", p[i], index);
  }

  return 0;
}
Problem p03221 (C++)

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> cities(M);
  vector<tuple<int, int>> cities_id(M);
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    cities[i] = make_tuple(Y, P, i);
  }
  sort(cities.begin(), cities.end());

  vector<int> cities_number(M, 0);
  for (auto &city : cities) {
    int P = get<1>(city);
    int i = get<2>(city);
    cities_number[P - 1]++;
    cities_id[i] = make_tuple(P, cities_number[P - 1]);
  }
  for (auto &city_id : cities_id) {
    cout << setfill('0') << right << setw(6) << get<0>(city_id);
    cout << setfill('0') << right << setw(6) << get<1>(city_id) << endl;
  }

  return 0;
}


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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> cities(M);
  vector<tuple<int, int>> cities_id(M);
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    cities[i] = make_tuple(Y, P, i);
  }
  sort(cities.begin(), cities.end());

  vector<int> cities_number(N, 0);
  for (auto &city : cities) {
    int P = get<1>(city);
    int i = get<2>(city);
    cities_number[P - 1]++;
    cities_id[i] = make_tuple(P, cities_number[P - 1]);
  }
  for (auto &city_id : cities_id) {
    cout << setfill('0') << right << setw(6) << get<0>(city_id);
    cout << setfill('0') << right << setw(6) << get<1>(city_id) << endl;
  }

  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> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> void PrintVector(const vector<T> &vec) {
  for (auto val : vec)
    cout << val << " ";
  cout << endl;
}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); // 3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

  for (auto &v : a) {
    sort(ALL(v));
  }

  rep(i, m) {
    auto b = find(ALL(a[p[i]]), y[i]);
    int index = distance(a[p[i]].begin(), b);
    printf("%06d%06d\n", p[i] + 1, index + 1);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> void PrintVector(const vector<T> &vec) {
  for (auto val : vec)
    cout << val << " ";
  cout << endl;
}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); // 3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

  for (auto &v : a) {
    sort(ALL(v));
  }

  rep(i, m) {
    // auto b = find(ALL(a[p[i]]), y[i]);
    // int index = distance(a[p[i]].begin(), b);
    int index =
        lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin();
    printf("%06d%06d\n", p[i] + 1, index + 1);
  }
}
Problem p03222 (C++)

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

typedef long long ll;
ll mod = 1e9 + 7;

ll dp[10][10];
ll fib[20];

int main() {
  ll h, w, k;
  cin >> h >> w >> k;
  fib[0] = 0, fib[1] = 1;
  for (int i = 2; i < 20; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
  dp[0][1] = 1;
  for (int i = 2; i <= w; i++)
    dp[0][i] = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      dp[i][j] = (dp[i - 1][j - 1] * fib[w - j + 1] % mod * fib[j - 1] % mod +
                  dp[i - 1][j + 1] * fib[w - j] % mod * fib[j] % mod +
                  dp[i - 1][j] * fib[j] % mod * fib[w - j + 1] % mod) %
                 mod;
    }
  }
  cout << dp[h][k] << endl;
}

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

typedef long long ll;
ll mod = 1e9 + 7;

ll dp[110][10];
ll fib[20];

int main() {
  ll h, w, k;
  cin >> h >> w >> k;
  fib[0] = 0, fib[1] = 1;
  for (int i = 2; i < 20; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
  dp[0][1] = 1;
  for (int i = 2; i <= w; i++)
    dp[0][i] = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      dp[i][j] = (dp[i - 1][j - 1] * fib[w - j + 1] % mod * fib[j - 1] % mod +
                  dp[i - 1][j + 1] * fib[w - j] % mod * fib[j] % mod +
                  dp[i - 1][j] * fib[j] % mod * fib[w - j + 1] % mod) %
                 mod;
    }
  }
  cout << dp[h][k] << endl;
}
Problem p03222 (C++)

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

const ll MOD = 1e9 + 7;
ll dp[16][9];
// dp[i][j]:上からiの高さまでの1から出発した時の数
ll h, w, k;

bool invalid(ll bit) {
  for (ll i = 0; i < w - 1; ++i) {
    if ((bit) & (1 << i) && (bit) & (1 << (i + 1))) {
      // cout<<bit<<endl;
      return true;
    }
  }
  return false;
}

int main() {
  cin >> h >> w >> k;
  dp[0][0] = 1;
  for (ll i = 0; i < h; ++i) {
    for (ll bit = 0; bit < (1 << (w - 1)); ++bit) {
      if (invalid(bit))
        continue;
      for (ll j = 0; j < w - 1; j++) {
        if (bit & (1 << j)) {
          (dp[i + 1][j] += dp[i][j + 1]) %= MOD;
          (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
          j++;
        } else {
          (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
      }
      if (!(bit & (1 << (w - 2)))) {
        // cout<<bit<<endl;
        (dp[i + 1][w - 1] += dp[i][w - 1]) %= MOD;
      }
    }
  }
  // for(ll i = 0;i<=h;i++){for(ll j = 0;j<w;j++){cout<<dp[i][j]<<'
  // ';}cout<<endl;}
  cout << dp[h][k - 1] << endl;
  return 0;
}

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

const ll MOD = 1e9 + 7;
ll dp[101][9];
// dp[i][j]:上からiの高さまでの1から出発した時の数
ll h, w, k;

bool invalid(ll bit) {
  for (ll i = 0; i < w - 1; ++i) {
    if ((bit) & (1 << i) && (bit) & (1 << (i + 1))) {
      // cout<<bit<<endl;
      return true;
    }
  }
  return false;
}

int main() {
  cin >> h >> w >> k;
  dp[0][0] = 1;
  for (ll i = 0; i < h; ++i) {
    for (ll bit = 0; bit < (1 << (w - 1)); ++bit) {
      if (invalid(bit))
        continue;
      for (ll j = 0; j < w - 1; j++) {
        if (bit & (1 << j)) {
          (dp[i + 1][j] += dp[i][j + 1]) %= MOD;
          (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
          j++;
        } else {
          (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
      }
      if (!(bit & (1 << (w - 2)))) {
        // cout<<bit<<endl;
        (dp[i + 1][w - 1] += dp[i][w - 1]) %= MOD;
      }
    }
  }
  // for(ll i = 0;i<=h;i++){for(ll j = 0;j<w;j++){cout<<dp[i][j]<<'
  // ';}cout<<endl;}
  cout << dp[h][k - 1] << endl;
  return 0;
}
Problem p03222 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

int main(void) {

  int h, w, k;
  cin >> h;
  cin >> w;
  cin >> k;
  const int mod = 1000000007;

  vector<vector<uint64_t>> num(w, vector<uint64_t>(101, 0));
  num[0][0] = 1;

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

    for (int j = 0; j < w; j++) {
      // num[j][i+1] = num[j][i];
      for (int k = 0; k < (1 << (w - 1)); k++) {

        bool check = true;
        for (int l = 0; l < w - 2; l++) {
          if ((k >> l) & 1 && (k >> l + 1) & 1)
            check = false;
        }

        if (!check)
          continue;

        if (j >= 1 && (k >> (j - 1)) & 1) {
          num[j - 1][i + 1] += num[j][i];
          num[j - 1][i + 1] %= mod;
        } else if (j <= w - 2 && (k >> j) & 1) {
          num[j + 1][i + 1] += num[j][i];
          num[j + 1][i + 1] %= mod;
        } else {
          num[j][i + 1] += num[j][i];
          num[j][i + 1] %= mod;
        }
      }
      // cout << endl;
      // cout << num[j][i] << " ";
      // cout << log10(num[j][i]) << " ";
      // cout << endl;
      // num[j][i]%=(uint64_t)1000000007;
    }
    // cout << num[0][i] << endl;
    // cout << endl;
  }

  // cout << (uint64_t)(num[k-1][h]%(uint64_t)1000000007) << endl;
  cout << num[k - 1][h] << endl;
  // uint64_t ans=num[k-1][h]%mod;
  // cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(void) {

  int h, w, k;
  cin >> h;
  cin >> w;
  cin >> k;
  const int mod = 1000000007;

  vector<vector<uint64_t>> num(w, vector<uint64_t>(102, 0));
  num[0][0] = 1;

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

    for (int j = 0; j < w; j++) {
      // num[j][i+1] = num[j][i];
      for (int k = 0; k < (1 << (w - 1)); k++) {

        bool check = true;
        for (int l = 0; l < w - 2; l++) {
          if ((k >> l) & 1 && (k >> l + 1) & 1)
            check = false;
        }

        if (!check)
          continue;

        if (j >= 1 && (k >> (j - 1)) & 1) {
          num[j - 1][i + 1] += num[j][i];
          num[j - 1][i + 1] %= mod;
        } else if (j <= w - 2 && (k >> j) & 1) {
          num[j + 1][i + 1] += num[j][i];
          num[j + 1][i + 1] %= mod;
        } else {
          num[j][i + 1] += num[j][i];
          num[j][i + 1] %= mod;
        }
      }
      // cout << endl;
      // cout << num[j][i] << " ";
      // cout << log10(num[j][i]) << " ";
      // cout << endl;
      // num[j][i]%=(uint64_t)1000000007;
    }
    // cout << num[0][i] << endl;
    // cout << endl;
  }

  // cout << (uint64_t)(num[k-1][h]%(uint64_t)1000000007) << endl;
  cout << num[k - 1][h] << endl;
  // uint64_t ans=num[k-1][h]%mod;
  // cout << ans << endl;

  return 0;
}