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

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

using namespace std;

int main(void) {
  int apple = 0;
  int apple_block = 0;
  int apple_pie = 0;

  cin >> apple;
  cin >> apple_block;

  apple_pie = ((3 * apple) + apple_block) / 2;

  cout << apple_pie << endl;

  return apple_pie;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int apple = 0;
  int apple_block = 0;
  int apple_pie = 0;

  cin >> apple;
  cin >> apple_block;

  apple_pie = ((3 * apple) + apple_block) / 2;

  cout << apple_pie << endl;

  return 0;
}
Problem p03029 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/numeric>
#define __                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pi acos(-1)
#define ll long long int
#define mem(a) memset(a, 0, sizeof(a))
#define mems(a) memset(a, -1, sizeof(a))
#define pii pair<int, int>
#define N 100005
using namespace std;

int main() {
  __;

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int a, p;

  cin >> a >> p;

  cout << ((3 * a) + p) / 2;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/numeric>
#define __                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pi acos(-1)
#define ll long long int
#define mem(a) memset(a, 0, sizeof(a))
#define mems(a) memset(a, -1, sizeof(a))
#define pii pair<int, int>
#define N 100005
using namespace std;

int main() {
  __;

#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
#endif

  int a, p;

  cin >> a >> p;

  cout << ((3 * a) + p) / 2;

  return 0;
}
Problem p03029 (C++)

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

int main() {
  int a, p;
  std::cin >> a >> p;
  std::cout << (a * 3 + p) / 2 << std::endl;

  return 1;
}


Fixed submission:
#include <iostream>

int main() {
  int a, p;
  std::cin >> a >> p;
  std::cout << (a * 3 + p) / 2 << std::endl;

  return 0;
}
Problem p03029 (C++)

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int A, P;
  cin >> A >> P;
  cout << 3 * A / P << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int A, P;
  cin >> A >> P;
  cout << (3 * A + P) / 2 << endl;

  return 0;
}
Problem p03029 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a * 3;
  d = c + b;

  cout << d % 0 << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a * 3;
  d = c + b;

  cout << d / 2 << endl;
}
Problem p03029 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  int a, p;
  cin >> a >> p;
  cout << 3 * a / p << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  int a, p;
  cin >> a >> p;
  cout << (3 * a + p) / 2 << endl;
}
Problem p03029 (C++)

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

int main(int argc, char *argv[]) {
  int A = atoi(argv[1]);
  int P = atoi(argv[2]);

  printf("%d\n", ((3 * A) + P) / 2);
  return 0;
}


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

int main() {
  int A;
  int P;
  scanf("%d %d\n", &A, &P);
  int a = 3 * A + P;
  int b = (a - a % 2) / 2;
  printf("%d\n", b);
  return 0;
}
Problem p03029 (Python)

Buggy submission (status: Runtime Error):
A, P = map(int, input.split(" "))
print((3 * A + P) // 2)


Fixed submission:
A, P = map(int, input().split(" "))
print((3 * A + P) // 2)
Problem p03029 (Python)

Buggy submission (status: Runtime Error):
a, p = map(int, input())
print((3 * a + p) // 2)


Fixed submission:
a, p = map(int, input().split())
print((3 * a + p) // 2)
Problem p03029 (C++)

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

int main(void) {
  int a, p;
  cin >> a >> p;
  cout << (3 * a) / p;
  return 0;
}

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

int main(void) {
  int a, p;
  cin >> a >> p;
  int kep = 3 * a + p;
  cout << kep / 2;
  return 0;
}
Problem p03030 (C++)

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

int main() {
  string A[20], sub1;
  int B[20], sub2, C[20], N;
  int i, j;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    C[i] = i + 1;
  }
  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      if (A[i] >= A[j]) {
        sub1 = A[i];
        A[i] = A[j];
        A[j] = sub1;
        sub2 = B[i];
        B[i] = B[j];
        B[j] = sub2;
        sub2 = C[i];
        C[i] = C[j];
        C[j] = sub2;
      }
    }
  }
  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      if (A[i] == A[j]) {
        if (B[i] < B[j]) {
          sub1 = A[i];
          A[i] = A[j];
          A[j] = sub1;
          sub2 = B[i];
          B[i] = B[j];
          B[j] = sub2;
          sub2 = C[i];
          C[i] = C[j];
          C[j] = sub2;
        }
      }
    }
  }
  for (i = 0; i < N; i++)
    cout << C[i] << endl;
  return 0;
}

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

int main() {
  string A[100], sub1;
  int B[100], sub2, C[100], N;
  int i, j;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    C[i] = i + 1;
  }
  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      if (A[i] >= A[j]) {
        sub1 = A[i];
        A[i] = A[j];
        A[j] = sub1;
        sub2 = B[i];
        B[i] = B[j];
        B[j] = sub2;
        sub2 = C[i];
        C[i] = C[j];
        C[j] = sub2;
      }
    }
  }
  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      if (A[i] == A[j]) {
        if (B[i] < B[j]) {
          sub1 = A[i];
          A[i] = A[j];
          A[j] = sub1;
          sub2 = B[i];
          B[i] = B[j];
          B[j] = sub2;
          sub2 = C[i];
          C[i] = C[j];
          C[j] = sub2;
        }
      }
    }
  }
  for (i = 0; i < N; i++)
    cout << C[i] << endl;
  return 0;
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)

map<string, ll> m;
int main() {
  ll n;
  cin >> n;
  string str[100];
  ll point[100];
  ll ans[100];
  repe(i, 1, n) {
    string s;
    cin >> str[i];
    ll p;
    cin >> point[i];
    m[str[i]]++;
  }

  for (map<string, ll>::iterator it = m.begin(); it != m.end(); it++) {
    string s1 = it->first;
    vector<pair<ll, ll>> v;
    repe(i, 1, n) {
      if (s1 == str[i]) {
        v.push_back(make_pair(point[i], i));
      }
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (vector<pair<ll, ll>>::iterator it = v.begin(); it != v.end(); it++) {
      cout << it->second << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
static const ll INF = (ll)1 << 62;
static const ll MOD = 1e9 + 7;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)

map<string, ll> m;
int main() {
  ll n;
  cin >> n;
  string str[101];
  ll point[101];
  repe(i, 1, n) {
    string s;
    cin >> str[i];
    ll p;
    cin >> point[i];
    m[str[i]]++;
  }

  for (map<string, ll>::iterator it = m.begin(); it != m.end(); it++) {
    string s1 = it->first;
    vector<pair<ll, ll>> v;
    repe(i, 1, n) {
      if (s1 == str[i]) {
        v.push_back(make_pair(point[i], i));
      }
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (vector<pair<ll, ll>>::iterator it = v.begin(); it != v.end(); it++) {
      cout << it->second << endl;
    }
  }
  return 0;
}
Problem p03030 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<pair<string, int>> Guide(N + 1);
  for (int i = 1; i <= N; i++) {
    string S;
    int P;
    cin >> S >> P;
    Guide[i] = {S, P};
  }
  vector<int> Index(N);
  iota(Index.begin(), Index.end(), 1);

  sort(Index.begin(), Index.end(), [Guide](const auto &a, const auto &b) {
    if (Guide[a].first == Guide[b].first)
      return Guide[a].second > Guide[b].second;
    else
      Guide[a].first < Guide[b].first;
  });

  for (const auto &i : Index)
    cout << i << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<pair<string, int>> Guide(N + 1);
  for (int i = 1; i <= N; i++) {
    string S;
    int P;
    cin >> S >> P;
    Guide[i] = {S, P};
  }
  vector<int> Index(N);
  iota(Index.begin(), Index.end(), 1);

  sort(Index.begin(), Index.end(), [Guide](const auto &a, const auto &b) {
    if (Guide[a].first == Guide[b].first)
      return Guide[a].second > Guide[b].second;
    else
      return Guide[a].first < Guide[b].first;
  });

  for (const auto &i : Index)
    cout << i << endl;
}
Problem p03030 (C++)

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

int main() {
  long long N;
  cin >> N;
  using col = tuple<string, long long, long long>;
  vector<col> p(N);
  for (int i = 0; i < N; i++) {
    string a;
    int b;
    cin >> a >> b;
    auto g = make_tuple(a, b, i);
    p.at(i) = g;
  }

  sort(p.begin(), p.end());
  int i = 0;
  while (i < N) {
    int init = i;
    string p1 = get<0>(p.at(i));
    string p2 = get<0>(p.at(i + 1));
    while (p1 == p2) {
      i++;
      if (i == N - 1) {
        break;
      }
      p1 = p2;
      p2 = get<0>(p.at(i + 1));
    }
    int num = i - init + 1;
    vector<pair<int, int>> li(num);
    for (int j = 0; j < num; j++) {
      int a, b;
      tie(ignore, a, b) = p.at(j + init);
      auto l = make_pair(a, b);
      li.at(j) = l;
    }
    reverse(li.begin(), li.end());
    for (int j = 0; j < num; j++) {
      int b, k;
      string a;
      tie(a, ignore, ignore) = p.at(j + init);
      tie(b, k) = li.at(j);
      auto g = make_tuple(a, b, k);
      p.at(j + init) = g;
    }
    i++;
  }
  for (int i = 0; i < N; i++) {
    cout << get<2>(p.at(i)) + 1 << endl;
  }
}

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

int main() {
  long long N;
  cin >> N;
  using col = tuple<string, long long, long long>;
  vector<col> p(N);
  for (int i = 0; i < N; i++) {
    string a;
    int b;
    cin >> a >> b;
    auto g = make_tuple(a, b, i);
    p.at(i) = g;
  }

  sort(p.begin(), p.end());
  int i = 0;
  while (i < N) {
    if (i == N - 1) {
      break;
    }
    int init = i;
    string p1 = get<0>(p.at(i));
    string p2 = get<0>(p.at(i + 1));
    while (p1 == p2) {
      i++;
      if (i == N - 1) {
        break;
      }
      p1 = p2;
      p2 = get<0>(p.at(i + 1));
    }
    int num = i - init + 1;
    vector<pair<int, int>> li(num);
    for (int j = 0; j < num; j++) {
      int a, b;
      tie(ignore, a, b) = p.at(j + init);
      auto l = make_pair(a, b);
      li.at(j) = l;
    }
    reverse(li.begin(), li.end());
    for (int j = 0; j < num; j++) {
      int b, k;
      string a;
      tie(a, ignore, ignore) = p.at(j + init);
      tie(b, k) = li.at(j);
      auto g = make_tuple(a, b, k);
      p.at(j + init) = g;
    }
    i++;
  }
  for (int i = 0; i < N; i++) {
    cout << get<2>(p.at(i)) + 1 << endl;
  }
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
/**
 *	  Name: Ajay Subhash Jadhav
 *	  Institute: International Institute of Technology Hyderabad
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int, int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
struct resto {
  string city;
  int points;
  int id;
};

bool cmp(resto a, resto b) {
  if (a.city == b.city)
    return a.points > b.points;
  return a.city < b.city;
}

int main() {

  fastio();
  inputread();
  int n, m, i, j, t;
  cin >> n;
  vector<resto> a;
  for (i = 1; i <= n; i++) {
    resto r;
    cin >> r.city >> r.points;
    r.id = i;
    a.pb(r);
  }
  sort(a.begin(), a.end(), cmp);
  for (i = 0; i < n; i++)
    cout << a[i].id << "\n";
  return 0;
}

Fixed submission:
/**
 *	  Name: Ajay Subhash Jadhav
 *	  Institute: International Institute of Technology Hyderabad
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int, int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
struct resto {
  string city;
  int points;
  int id;
};

bool cmp(resto a, resto b) {
  if (a.city == b.city)
    return a.points > b.points;
  return a.city < b.city;
}

int main() {

  fastio();
  int n, m, i, j, t;
  cin >> n;
  vector<resto> a;
  for (i = 1; i <= n; i++) {
    resto r;
    cin >> r.city >> r.points;
    r.id = i;
    a.pb(r);
  }
  sort(a.begin(), a.end(), cmp);
  for (i = 0; i < n; i++)
    cout << a[i].id << "\n";
  return 0;
}
Problem p03030 (C++)

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

struct info {
  string cn;
  int score, sn;

  bool operator<(const info &rhs) {
    if (cn != rhs.cn)
      return cn < rhs.cn;
    return score > rhs.score;
  }
} cities[100];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> cities[i].cn >> cities[i].score;
    cities[i].sn = i;
  }
  sort(cities, cities + n + 1);
  for (int i = 1; i <= n; i++) {
    cout << cities[i].sn << "\n";
  }
}


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

struct info {
  string cn;
  int score, sn;

  bool operator<(const info &rhs) {
    if (cn != rhs.cn)
      return cn < rhs.cn;
    return score > rhs.score;
  }
} cities[103];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> cities[i].cn >> cities[i].score;
    cities[i].sn = i;
  }
  sort(cities, cities + n + 1);
  for (int i = 1; i <= n; i++) {
    cout << cities[i].sn << "\n";
  }
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (long long i = 0; i < n; i++)
#define REP1(i, n) for (long long i = 1; i <= n; i++)
#define ITE(arr) for (auto ite = (arr).begin(); ite != (arr).end(); ite++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
typedef long long ll;
typedef pair<int, int> pii;
//---------------------
#define MAXN
//---------------------
ll n, p;
string s;

typedef pair<string, int> psi;
vector<psi> vec;

bool mysort(psi a, psi b) {
  bool ret = false;
  if (a.first == b.first) {
    ret = (a.second % 1000) > (b.second % 1000);

  } else {
    int id = 0;

    while (a.first[id] == b.first[id]) {
      id++;
      if (id >= a.first.length()) {
        ret = true;
        break;
      }
      if (id >= b.first.length()) {
        ret = false;
        break;
      }
    }
    ret = a.first[id] < b.first[id];
  }
}

int main() {
  cin >> n;
  REP(i, n) {
    cin >> s >> p;
    vec.push_back(psi(s, p + (i + 1) * 1000));
  }
  sort(ALL(vec), mysort);
  REP(i, n) cout << vec[i].second / 1000 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (long long i = 0; i < n; i++)
#define REP1(i, n) for (long long i = 1; i <= n; i++)
#define ITE(arr) for (auto ite = (arr).begin(); ite != (arr).end(); ite++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
typedef long long ll;
typedef pair<int, int> pii;
//---------------------
#define MAXN
//---------------------
ll n, p;
string s;

typedef pair<string, int> psi;
vector<psi> vec;

bool mysort(psi a, psi b) {
  bool ret = false;
  if (a.first == b.first) {
    ret = (a.second % 1000) > (b.second % 1000);

  } else {
    int id = 0;

    while (a.first[id] == b.first[id]) {
      id++;
      if (id >= a.first.length()) {
        ret = true;
        break;
      }
      if (id >= b.first.length()) {
        ret = false;
        break;
      }
    }
    ret = a.first[id] < b.first[id];
  }
  return ret;
}

int main() {
  cin >> n;
  REP(i, n) {
    cin >> s >> p;
    vec.push_back(psi(s, p + (i + 1) * 1000));
  }
  sort(ALL(vec), mysort);
  REP(i, n) cout << vec[i].second / 1000 << endl;
  return 0;
}
Problem p03030 (C++)

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

bool compare(const pair<string, pair<int, int>> &a,
             const pair<string, pair<int, int>> &b) {
  if (a.first < b.first)
    return true;
  if (a.first == b.first)
    return a.second.first > b.second.first;
}
int main() {
  vector<pair<string, pair<int, int>>> v;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string temp;
    int score;
    cin >> temp;
    cin >> score;
    v.push_back(make_pair(temp, make_pair(score, i)));
  }
  sort(v.begin(), v.end(), compare);
  for (int i = 0; i < v.size(); i++)
    cout << v[i].second.second + 1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INF 2e9 + 5
#define ll long long

bool compare(const pair<string, pair<int, int>> &a,
             const pair<string, pair<int, int>> &b) {
  if (a.first < b.first)
    return true;
  if (a.first == b.first)
    return a.second.first > b.second.first;
  return false;
}
int main() {
  vector<pair<string, pair<int, int>>> v;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string temp;
    int score;
    cin >> temp;
    cin >> score;
    v.push_back(make_pair(temp, make_pair(score, i)));
  }
  sort(v.begin(), v.end(), compare);
  for (int i = 0; i < v.size(); i++)
    cout << v[i].second.second + 1 << endl;
  return 0;
}
Problem p03030 (C++)

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

using namespace std;

int main() {
  int n;
  vector<pair<string, int>> array, copy;

  cin >> n;
  array.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> array[i].first >> array[i].second;
  }
  copy = array;
  sort(array.begin(), array.end());

  for (int j = 0; j < array.size() - 1; j++) {
    if (array[j].first == array[j + 1].first) {
      int num = 0;
      while (array[j + num].first == array[j].first) {
        num++;
      }
      partial_sort(array.begin() + j, array.begin() + j + num,
                   array.begin() + j + num, greater<pair<string, int>>());
    }
  }

  for (int k = 0; k < array.size(); k++) {
    int m = 0;
    while (copy[m] != array[k]) {
      m++;
    }
    cout << m + 1 << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int n;
  vector<pair<string, int>> array, copy;

  cin >> n;
  array.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> array[i].first >> array[i].second;
  }
  copy = array;
  sort(array.begin(), array.end());

  for (int j = 0; j < array.size() - 1; j++) {
    if (array[j].first == array[j + 1].first) {
      int num = 1;
      while (true) {
        if (j + num >= array.size()) {
          break;
        } else if (array[j].first != array[j + num].first) {
          break;
        }
        num++;
      }
      partial_sort(array.begin() + j, array.begin() + j + num,
                   array.begin() + j + num, greater<pair<string, int>>());
    }
  }

  for (int k = 0; k < array.size(); k++) {
    int m = 0;
    while (copy[m] != array[k]) {
      m++;
    }
    cout << m + 1 << endl;
  }
  return 0;
}
Problem p03030 (C++)

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

int main() {
  int i, j;
  int num;
  scanf("%d", &num);

  /* 文字列 */
  int score[101];
  int sort[101];
  char moji[101][10], tmp[10];
  int test;

  /* 3つの文字列を入力 */
  for (i = 1; i < num + 1; i++) {
    sort[i] = i;
    scanf("%s %d", moji[i], &score[i]);
  }

  for (i = 2; i < num + 1; i++) {
    for (j = 2; j < num + 1; j++) {
      if (strcmp(moji[j - 1], moji[j]) > 0) {

        strcpy(tmp, moji[j - 1]);
        strcpy(moji[j - 1], moji[j]);
        strcpy(moji[j], tmp);
        test = score[j - 1];
        score[j - 1] = score[j];
        score[j] = test;
        test = sort[j - 1];
        sort[j - 1] = sort[j];
        sort[j] = test;

      } else if (strcmp(moji[j - 1], moji[j]) == 0) {
        if (score[j - 1] < score[j]) {
          strcpy(tmp, moji[j - 1]);
          strcpy(moji[j - 1], moji[j]);
          strcpy(moji[j], tmp);
          test = score[j - 1];
          score[j - 1] = score[j];
          score[j] = test;
          test = sort[j - 1];
          sort[j - 1] = sort[j];
          sort[j] = test;
        }
      }
    }
  }

  for (i = 1; i < num + 1; i++) {
    printf("%d\n", sort[i]);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main() {
  int i, j;
  int num;
  scanf("%d", &num);

  /* 文字列 */
  int score[101];
  int sort[101];
  char moji[101][20], tmp[20];
  int test;

  /* 3つの文字列を入力 */
  for (i = 1; i < num + 1; i++) {
    sort[i] = i;
    scanf("%s %d", moji[i], &score[i]);
  }

  for (i = 2; i < num + 1; i++) {
    for (j = 2; j < num + 1; j++) {
      if (strcmp(moji[j - 1], moji[j]) > 0) {

        strcpy(tmp, moji[j - 1]);
        strcpy(moji[j - 1], moji[j]);
        strcpy(moji[j], tmp);
        test = score[j - 1];
        score[j - 1] = score[j];
        score[j] = test;
        test = sort[j - 1];
        sort[j - 1] = sort[j];
        sort[j] = test;

      } else if (strcmp(moji[j - 1], moji[j]) == 0) {
        if (score[j - 1] < score[j]) {
          strcpy(tmp, moji[j - 1]);
          strcpy(moji[j - 1], moji[j]);
          strcpy(moji[j], tmp);
          test = score[j - 1];
          score[j - 1] = score[j];
          score[j] = test;
          test = sort[j - 1];
          sort[j - 1] = sort[j];
          sort[j] = test;
        }
      }
    }
  }

  for (i = 1; i < num + 1; i++) {
    printf("%d\n", sort[i]);
  }

  return 0;
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  pair<pair<string, int>, int> a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    string x;
    cin >> x;
    cin >> b;
    a[i] = make_pair(make_pair(x, b), i);
  }
  for (int i = 0; i < n - 1; i++)
    for (int j = n; j >= i + 1; j--) {
      if (a[j - 1].first.first < a[j].first.first) {
        swap(a[j - 1], a[j]);
      }
      if (a[j - 1].first.first == a[j].first.first)
        if (a[j - 1].first.second > a[j].first.second) {
          swap(a[j - 1], a[j]);
        }
    }
  for (int i = 0; i < n; i++) {
    cout << a[n - i - 1].second + 1 << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  pair<pair<string, int>, int> a[111];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    string x;
    cin >> x;
    cin >> b;
    a[i] = make_pair(make_pair(x, b), i);
  }
  for (int i = 0; i < n - 1; i++)
    for (int j = n; j >= i + 1; j--) {
      if (a[j - 1].first.first < a[j].first.first) {
        swap(a[j - 1], a[j]);
      }
      if (a[j - 1].first.first == a[j].first.first)
        if (a[j - 1].first.second > a[j].first.second) {
          swap(a[j - 1], a[j]);
        }
    }
  for (int i = 0; i < n; i++) {
    cout << a[n - i - 1].second + 1 << endl;
  }
  return 0;
}
Problem p03030 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = []
for i in range(n):
    s, p = list(map(int, input().split()))
    a.append((s, -int(p), i))
a.sort()

for _, _, i in a:
    print(i + 1)


Fixed submission:
n = int(input())
a = []
for i in range(n):
    s, p = input().split()
    a.append((s, -int(p), i))
a.sort()

for _, _, i in a:
    print(i + 1)
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> V(N);
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    int P;
    cin >> P;
    V[i] = pair<pair<string, int>, int>(pair<string, int>(S, P), i + 1);
  }

  sort(V.begin(), V.end());
  for (int i = 0; i < N; i++) {
    string C = V[i].fs.fs;
    int j = i + 1;
    int p = i;
    while (V[j].fs.fs == C) {
      j++;
      i++;
      if (j >= N || i >= N)
        break;
    }
    reverse(V.begin() + p, V.begin() + j);
  }

  for (int i = 0; i < N; i++) {
    cout << V[i].sc << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> V(N);
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    int P;
    cin >> P;
    V[i] = pair<pair<string, int>, int>(pair<string, int>(S, P), i + 1);
  }

  sort(V.begin(), V.end());
  for (int i = 0; i < N; i++) {
    string C = V[i].fs.fs;
    int j = i + 1;
    if (j >= N)
      break;
    int p = i;
    while (V[j].fs.fs == C) {
      j++;
      i++;
      if (j >= N || i >= N)
        break;
    }
    reverse(V.begin() + p, V.begin() + j);
  }

  for (int i = 0; i < N; i++) {
    cout << V[i].sc << endl;
  }

  return 0;
}
Problem p03030 (C++)

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

int main() {

  int n;
  cin >> n;
  vector<tuple<string, int, int>> t;
  for (int i = 1; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    t.push_back(tie(s, p, i));
  }

  sort(t.begin(), t.end());
  for (int i = 0; i < n; i++) {
    cout << get<2>(t[i]) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;

int main() {

  int n;
  cin >> n;
  vector<tuple<string, int, int>> t;
  for (int i = 1; i < n + 1; i++) {
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    t.push_back(tie(s, p, i));
  }

  sort(t.begin(), t.end());
  for (int i = 0; i < n; i++) {
    cout << get<2>(t[i]) << endl;
  }
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<string, int> guide;

int main() {
  int N;
  cin >> N;
  vector<guide> G;
  vector<guide> C;
  for (int i = 0; i < N; i++) {
    string s;
    int p;
    cin >> s >> p;
    G.push_back(guide(s, p));
    C.push_back(guide(s, p));
  }

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = N - 1; j >= i - 1; j--) {
      if (C[j].first == C[j - 1].first) {
        if (C[j].second > C[j - 1].second) {
          guide tmp = C[j];
          C[j] = C[j - 1];
          C[j - 1] = tmp;
        }
      }
    }
  }

  for (int i = 0; i < N; i++) {
    guide c = C[i];
    for (int j = 0; j < N; j++) {
      if (c == G[j])
        cout << j + 1 << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<string, int> guide;

int main() {
  int N;
  cin >> N;
  vector<guide> G;
  vector<guide> C;
  for (int i = 0; i < N; i++) {
    string s;
    int p;
    cin >> s >> p;
    G.push_back(guide(s, p));
    C.push_back(guide(s, p));
  }

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = N - 1; j >= i + 1; j--) {
      if (C[j].first == C[j - 1].first) {
        if (C[j].second > C[j - 1].second) {
          guide tmp = C[j];
          C[j] = C[j - 1];
          C[j - 1] = tmp;
        }
      }
    }
  }

  for (int i = 0; i < N; i++) {
    guide c = C[i];
    for (int j = 0; j < N; j++) {
      if (c == G[j])
        cout << j + 1 << endl;
    }
  }

  return 0;
}
Problem p03030 (C++)

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("outp.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  map<string, vector<pair<int, int>>> m;
  for (int i = 1; i <= n; i++) {
    string s;
    int x;
    cin >> s >> x;
    m[s].push_back({x, i});
  }
  for (auto &i : m) {
    sort(i.ss.begin(), i.ss.end(), greater<pair<int, int>>());
    for (auto j : i.ss)
      cout << j.ss << endl;
  }

  return 0;
}

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

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

  int n;
  cin >> n;
  map<string, vector<pair<int, int>>> m;
  for (int i = 1; i <= n; i++) {
    string s;
    int x;
    cin >> s >> x;
    m[s].push_back({x, i});
  }
  for (auto &i : m) {
    sort(i.ss.begin(), i.ss.end(), greater<pair<int, int>>());
    for (auto j : i.ss)
      cout << j.ss << endl;
  }

  return 0;
}
Problem p03030 (C++)

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

int main() {
  int num_of_tuple = 0;
  cin >> num_of_tuple;

  string a;
  int b = 0;

  vector<tuple<string, int, int>> v(num_of_tuple);

  for (int i = 0; i < num_of_tuple; ++i) {
    cin >> a >> b;
    v.at(i) =
        make_tuple(a, b, 1 + i); // 3番目の要素にインデックスの代わりを入れる
  }

  // 市名順にソート
  sort(
      v.begin(), v.end(),
      [](const tuple<string, int, int> &t1, const tuple<string, int, int> &t2) {
        if (get<0>(t1) != get<0>(t2)) {
          return get<0>(t1) < get<0>(t2);
        } else {
          get<1>(t1) > get<1>(t2);
        }
      });

  // ソートしたものを出力
  for (tuple<string, int, int> i : v) {
    string s;
    int x = 0, y = 0;
    tie(s, x, y) = i;
    // cout << s << " " << x << " " << y << endl;
    // //入っている要素を確かめるためのcout
    cout << y << endl;
  }
}


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

int main() {
  int num_of_tuple = 0;
  cin >> num_of_tuple;

  string a;
  int b = 0;

  vector<tuple<string, int, int>> v(num_of_tuple);

  for (int i = 0; i < num_of_tuple; ++i) {
    cin >> a >> b;
    v.at(i) =
        make_tuple(a, b, 1 + i); // 3番目の要素にインデックスの代わりを入れる
  }

  // 市名順にソート
  sort(
      v.begin(), v.end(),
      [](const tuple<string, int, int> &t1, const tuple<string, int, int> &t2) {
        if (get<0>(t1) != get<0>(t2)) {
          return get<0>(t1) < get<0>(t2);
        } else {
          return get<1>(t1) > get<1>(t2);
        }
      });

  // ソートしたものを出力
  for (tuple<string, int, int> i : v) {
    string s;
    int x = 0, y = 0;
    tie(s, x, y) = i;
    // cout << s << " " << x << " " << y << endl;
    // //入っている要素を確かめるためのcout
    cout << y << endl;
  }
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> P(N);
  vector<string> S(N), C(N);
  vector<int> Q(N), R(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i] >> P[i];
    C[i] = S[i];
    Q[i] = R[i] = 0;
  }

  sort(C.begin(), C.end());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (C[i] == S[j] && Q[i] < P[j]) {
        Q[i] = P[j];
        R[i] = j + 1;
      }
    }
    S[R[i] - 1] = "ZZZZZ";
    P[R[i] - 1] = 0;
  }
  for (int i = 0; i < N; i++) {
    cout << R[i] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> P(N);
  vector<string> S(N), C(N);
  vector<int> Q(N), R(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i] >> P[i];
    C[i] = S[i];
    Q[i] = R[i] = 0;
  }

  sort(C.begin(), C.end());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (C[i] == S[j] && Q[i] <= P[j]) {
        Q[i] = P[j];
        R[i] = j + 1;
      }
    }
    S[R[i] - 1] = "ZZZZZ";
    P[R[i] - 1] = 0;
  }
  for (int i = 0; i < N; i++) {
    cout << R[i] << endl;
  }
}
Problem p03030 (C++)

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

int main() {
  pair<pair<string, int>, int> p[120];
  int n, a;
  string s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", &s, &a);
    p[i] = make_pair(make_pair(s, -a), i);
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++)
    printf("%d\n", p[i].second + 1);
}

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

int main() {
  pair<pair<string, int>, int> p[120];
  int n, a;
  string s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s >> a;
    p[i] = make_pair(make_pair(s, -a), i);
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++)
    printf("%d\n", p[i].second + 1);
}
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
// in the name of god
// if you read this code please search about imam hussain
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define read                                                                   \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int del = 728729;
bool sortbysec(const pair<string, pair<int, int>> &a,
               const pair<string, pair<int, int>> &b) {
  if (a.first > b.first)
    return 1;
  if (a.first == b.first)
    return a.second.first < b.second.first;
}

int main() {
  migmig;
  vector<pair<string, pair<int, int>>> v;
  int n;
  cin >> n;
  string x;
  int y;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    v.pb(make_pair(x, make_pair(y, i)));
  }
  sort(v.begin(), v.end(), sortbysec);
  for (int i = n - 1; i >= 0; i--) {
    cout << v[i].second.second << endl;
  }

  return 0;
}

Fixed submission:
// in the name of god
// if you read this code please search about imam hussain
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define read                                                                   \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int del = 728729;
bool sortbysec(const pair<string, pair<int, int>> &a,
               const pair<string, pair<int, int>> &b) {
  if (a.first > b.first)
    return 1;
  if (a.first == b.first && a.second.first < b.second.first)
    return 1;
  return 0;
}

int main() {
  migmig;
  vector<pair<string, pair<int, int>>> v;
  int n;
  cin >> n;
  string x;
  int y;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    v.pb(make_pair(x, make_pair(y, i)));
  }
  sort(v.begin(), v.end(), sortbysec);
  for (int i = n - 1; i >= 0; i--) {
    cout << v[i].second.second << endl;
  }

  return 0;
}
Problem p03030 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
n = int(input())
res = [(i, *input().split()) for i in range(n)]

res.sort(key=lambda x: (x[1], -int(x[2])))

for r in res:
    print(r[0] + 1)


Fixed submission:
#!/usr/bin/env python3
n = int(input())
res = [[i] + input().split() for i in range(n)]

res.sort(key=lambda x: (x[1], -int(x[2])))

for r in res:
    print(r[0] + 1)
Problem p03030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, c[105];
vector<pair<string, int>> f;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    c[p] = i + 1;
    f.push_back({s, p});
  }
  sort(f.begin(), f.end());
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (f[i].first == f[i + 1].first && i != n) {
      cnt++;
      continue;
    } else {
      for (int j = i; cnt > 0; j--, cnt--) {
        cout << c[f[j].second] << endl;
      }
      cnt = 1;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, c[105];
vector<pair<string, int>> f;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    c[p] = i + 1;
    f.push_back({s, p});
  }
  sort(f.begin(), f.end());
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (i != n - 1) {
      if (f[i].first == f[i + 1].first) {
        cnt++;
      } else {
        for (int j = i; cnt > 0; j--, cnt--) {
          cout << c[f[j].second] << endl;
        }
        cnt = 1;
      }
    } else {
      for (int j = i; cnt > 0; j--, cnt--) {
        cout << c[f[j].second] << endl;
      }
      cnt = 1;
    }
  }
}
Problem p03030 (C++)

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

int main() {
  int N;
  cin >> N;
  string RestrunStr[100];
  int RestrunNum[100];

  for (int i = 1; i <= N; i++) {
    int P;
    string S;
    cin >> S >> P;
    RestrunStr[i] = S;
    RestrunNum[i] = P;
  }

  map<int, int> ans;
  int i = 1;
  int num = 1;
  for (i = 1; i <= N; i++) {
    num = 1;
    for (int j = 1; j <= N; j++) {
      if (RestrunStr[i] < RestrunStr[j]) {
      } else if (RestrunStr[i] == RestrunStr[j]) {
        if (RestrunNum[i] > RestrunNum[j]) {
        } else if (RestrunNum[i] == RestrunNum[j]) {
        } else {
          num++;
        }
      } else {
        num++;
      }
    }
    ans[num] = i;
  }

  for (int aa = 1; aa <= N; aa++) {
    cout << ans[aa] << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  string RestrunStr[255];
  int RestrunNum[255];

  for (int i = 1; i <= N; i++) {
    int P;
    string S;
    cin >> S >> P;
    RestrunStr[i] = S;
    RestrunNum[i] = P;
  }

  map<int, int> ans;
  int i = 1;
  int num = 1;
  for (i = 1; i <= N; i++) {
    num = 1;
    for (int j = 1; j <= N; j++) {
      if (RestrunStr[i] < RestrunStr[j]) {
      } else if (RestrunStr[i] == RestrunStr[j]) {
        if (RestrunNum[i] > RestrunNum[j]) {
        } else if (RestrunNum[i] == RestrunNum[j]) {
        } else {
          num++;
        }
      } else {
        num++;
      }
    }
    ans[num] = i;
  }

  for (int aa = 1; aa <= N; aa++) {
    cout << ans[aa] << endl;
  }
}
Problem p03030 (C++)

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

int main() {
  char in[120];
  pair<pair<string, int>, int> p[11];

  int a;
  cin >> a;

  for (int i = 0; i < a; i++) {
    int t;
    cin >> in >> t;
    // string tmp = in;
    p[i] = make_pair(make_pair(in, -t), i);
  }

  sort(p, p + a);

  for (int i = 0; i < a; i++) {
    cout << p[i].second + 1 << endl;
  }
}

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

int main() {
  char in[120];
  pair<pair<string, int>, int> p[110];

  int a;
  cin >> a;

  for (int i = 0; i < a; i++) {
    int t;
    cin >> in >> t;
    // string tmp = in;
    p[i] = make_pair(make_pair(in, -t), i);
  }

  sort(p, p + a);

  for (int i = 0; i < a; i++) {
    cout << p[i].second + 1 << endl;
  }
}
Problem p03030 (C++)

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

struct restaurant {
  int no;
  string name;
  int pt;
};

int cmp(const void *v1, const void *v2) {
  restaurant *r1 = (restaurant *)v1;
  restaurant *r2 = (restaurant *)v2;
  if (r1->name > r2->name)
    return 1;
  if (r1->name < r2->name)
    return -1;
  if (r1->pt > r2->pt)
    return -1;
  if (r1->pt < r2->pt)
    return 1;
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> p(n);
  rep(i, n) cin >> s[i] >> p[i];

  restaurant rs[109];
  rep(i, n) rs[i] = {.no = i + 1, .name = s[i], .pt = p[i]};
  qsort(rs, n, sizeof(restaurant), cmp);
  rep(i, n) cout << rs[i].no << endl;
  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>;

struct restaurant {
  int no;
  string name;
  int pt;
};

int cmp(const void *v1, const void *v2) {
  restaurant *r1 = (restaurant *)v1;
  restaurant *r2 = (restaurant *)v2;
  if (r1->name > r2->name)
    return 1;
  if (r1->name < r2->name)
    return -1;
  if (r1->pt > r2->pt)
    return -1;
  if (r1->pt < r2->pt)
    return 1;
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> p(n);
  rep(i, n) cin >> s[i] >> p[i];

  vector<pair<pair<string, int>, int>> r(n);
  rep(i, n) r[i] = make_pair(make_pair(s[i], -p[i]), i + 1);
  sort(r.begin(), r.end());
  rep(i, n) cout << r[i].second << endl;
  return 0;
}
Problem p03030 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
SP = [(i + 1, input().split()) for i in range(N)]
P = [[0, 0, 0] for _ in range(N)]
for i in range(N):
    P[i][0] = SP[i][0]
    P[i][1] = SP[i][1][0]
    P[i][2] = int(SP[i][1][1])
P.sort(key=lambda x: x[1][1], reverse=True)
P.sort(key=lambda x: x[1][0])

for p in P:
    print(p[0])


Fixed submission:
N = int(input())
SP = [(i + 1, input().split()) for i in range(N)]
P = [[0, 0, 0] for _ in range(N)]
for i in range(N):
    P[i][0] = SP[i][0]
    P[i][1] = SP[i][1][0]
    P[i][2] = int(SP[i][1][1])
P.sort(key=lambda x: x[2], reverse=True)
P.sort(key=lambda x: x[1])

for p in P:
    print(p[0])
Problem p03030 (Python)

Buggy submission (status: Runtime Error):
# input
N = int(input())
SA = [str(input()) for i in range(N)]

# process
cities = list(set([x.split()[0] for x in SA]))
cities.sort()

for y in cities:
    each_SA = [i for i in SA if y in i]
    each_points = [int(x.split()[1]) for x in each_SA]
    each_points.sort(reverse=True)
    for j in each_points:
        print(SA.index(y + " " + str(j)) + 1)


Fixed submission:
# input
N = int(input())
SA = [str(input()) for i in range(N)]

# process
cities = list(set([x.split()[0] for x in SA]))
cities.sort()

for y in cities:
    each_SA = []
    for i in SA:
        if i.split()[0] == y:
            each_SA.append(i)
    each_points = [int(x.split()[1]) for x in each_SA]
    each_points.sort(reverse=True)
    for j in each_points:
        print(SA.index(y + " " + str(j)) + 1)
Problem p03030 (Python)

Buggy submission (status: Runtime Error):
# ABC128-B
# ソートが大事な問題
import itemgetter

a = int(input())
book = []
for i in range(a):
    array = input().split()
    book.append((array[0], int(array[1]) * -1, i))

ans = sorted(book, key=itemgetter(0, 1))

for i in range(a):
    print(ans[i][2] + 1)


Fixed submission:
# ABC128-B
# ソートが大事な問題
from operator import itemgetter

a = int(input())
book = []
for i in range(a):
    array = input().split()
    book.append((array[0], int(array[1]) * -1, i))

ans = sorted(book, key=itemgetter(0, 1))

for i in range(a):
    print(ans[i][2] + 1)
Problem p03031 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      s[i] |= (1 << --a);
    }
  }
  vector<int> P(M);
  for (auto &p : P)
    cin >> p;
  int ans = 0;
  for (int b = 0; b < (1 << N); b++) {
    int ok = 1;
    for (int i = 0; i < M; i++) {
      int bb = b & s[i];
      int cnt = 0;
      while (bb) {
        cnt += (1 & bb);
        bb >>= 1;
      }
      cnt = (cnt & 1);
      if (cnt != P[i])
        ok = 0;
    }
    ans += ok;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      s[i] |= (1 << --a);
    }
  }
  vector<int> P(M);
  for (auto &p : P)
    cin >> p;
  int ans = 0;
  for (int b = 0; b < (1 << N); b++) {
    int ok = 1;
    for (int i = 0; i < M; i++) {
      int bb = b & s[i];
      int cnt = 0;
      while (bb) {
        cnt += (1 & bb);
        bb >>= 1;
      }
      cnt = (cnt & 1);
      if (cnt != P[i])
        ok = 0;
    }
    ans += ok;
  }
  cout << ans << endl;
  return 0;
}