alexjercan/bugnet huggingface dataset:
Problem p00193 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <vector>

using namespace std;

inline int dist(int x1, int y1, int x2, int y2) {
  if (y1 > y2) {
    swap(x1, x2);
    swap(y1, y2);
  }

  int dy = y2 - y1;
  if (y1 & 1)
    return max(max(x2 - x1 - dy / 2, x1 - x2 - (dy + 1) / 2), 0) + dy;
  else
    return max(max(x2 - x1 - (dy + 1) / 2, x1 - x2 - dy / 2), 0) + dy;
}

int main() {
  for (int w, h; scanf("%d%d", &w, &h), w;) {
    int s;
    scanf("%d", &s);
    vector<int> xs(s), ys(s);
    for (int i = 0; i < s; i++)
      scanf("%d%d", &xs[i], &ys[i]);
    int t;
    scanf("%d", &t);
    int res = 0;
    while (t--) {
      int x, y;
      scanf("%d%d", &x, &y);
      int tmp = 0;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          int d = 1 << 29;
          for (int k = 0; k < s; k++)
            d = min(d, dist(xs[k], ys[k], j, i));
          if (d > dist(x, y, j, i))
            tmp++;
        }
      }
      res = max(tmp, res);
    }
    printf("%d\\n", res);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int dist(int x1, int y1, int x2, int y2) {
  if (y1 > y2) {
    swap(x1, x2);
    swap(y1, y2);
  }

  int dy = y2 - y1;
  if (y1 & 1)
    return max(max(x2 - x1 - dy / 2, x1 - x2 - (dy + 1) / 2), 0) + dy;
  else
    return max(max(x2 - x1 - (dy + 1) / 2, x1 - x2 - dy / 2), 0) + dy;
}

int main() {
  for (int w, h; cin >> w >> h;) {
    int s;
    cin >> s;
    vector<int> xs(s), ys(s);
    for (int i = 0; i < s; i++)
      cin >> xs[i] >> ys[i];
    int t;
    cin >> t;
    int res = 0;
    while (t--) {
      int x, y;
      cin >> x >> y;
      int tmp = 0;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          int d = 1 << 29;
          for (int k = 0; k < s; k++)
            d = min(d, dist(xs[k], ys[k], j, i));
          if (d > dist(x, y, j, i))
            tmp++;
        }
      }
      res = max(tmp, res);
    }
    cout << res << endl;
  }

  return 0;
}
Problem p00193 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> grid;

const int INF = 1e9;
const int dx[6] = {0, 1, 1, 1, 0, -1}, dy[6] = {-1, -1, 0, 1, 1, 0};
int h, w;

grid bfs(int y, int x) {
  grid res(h, vi(w, INF));
  res[y][x] = 0;
  queue<int> q;
  q.push(y * w + x);

  while (q.size()) {
    y = q.front() / w;
    x = q.front() % w;
    q.pop();
    int c = res[y][x];

    for (int i = 0; i < 6; i++) {
      int ny = y + dy[i],
          nx = x + dx[i] + ((y % 2 == 0 && i % 3 != 2) ? -1 : 0);
      if (ny < 0 || nx < 0 || ny >= h || nx >= w)
        continue;
      if (res[ny][nx] > c + 1) {
        res[ny][nx] = c + 1;
        q.push(ny * w + nx);
      }
    }
  }
  return res;
}

int main() {
  while (cin >> w >> h, w) {
    grid g(h, vi(w, INF));

    int s;
    cin >> s;
    for (int z = 0; z < s; z++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      grid tmp = bfs(b, a);

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
          g[i][j] = min(g[i][j], tmp[i][j]);
      }
    }

    int t, res = 0;
    cin >> t;
    for (int z = 0; z < t; z++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      grid tmp = bfs(b, a);
      int cover = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (g[i][j] > tmp[i][j])
            cover++;
        }
      }
      res = max(res, cover);
    }

    cout << res << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> grid;

const int INF = 1e9;
const int dx[6] = {0, 1, 1, 1, 0, -1}, dy[6] = {-1, -1, 0, 1, 1, 0};
int h, w;

grid bfs(int y, int x) {
  grid res(h, vi(w, INF));
  res[y][x] = 0;
  queue<int> q;
  q.push(y * w + x);

  while (q.size()) {
    y = q.front() / w;
    x = q.front() % w;
    q.pop();
    int c = res[y][x];

    for (int i = 0; i < 6; i++) {
      int ny = y + dy[i],
          nx = x + dx[i] + ((y % 2 == 0 && i % 3 != 2) ? -1 : 0);
      if (ny < 0 || nx < 0 || ny >= h || nx >= w)
        continue;
      if (res[ny][nx] > c + 1) {
        res[ny][nx] = c + 1;
        q.push(ny * w + nx);
      }
    }
  }
  return res;
}

int main() {
  while (cin >> h >> w, h) {
    grid g(h, vi(w, INF));

    int s;
    cin >> s;
    for (int z = 0; z < s; z++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      grid tmp = bfs(b, a);

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
          g[i][j] = min(g[i][j], tmp[i][j]);
      }
    }

    int t, res = 0;
    cin >> t;
    for (int z = 0; z < t; z++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      grid tmp = bfs(b, a);
      int cover = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (g[i][j] > tmp[i][j])
            cover++;
        }
      }
      res = max(res, cover);
    }

    cout << res << endl;
  }
}
Problem p00195 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  while (1) {
    int max = -1;
    char c[5];
    c[0] = 'A';
    c[1] = 'B';
    c[2] = 'C';
    c[3] = 'D';
    c[4] = 'E';
    int maxchar = 0;

    for (int i = 0; i < 5; i++) {
      cin >> a >> b;
      if (a == 0 && b == 0)
        break;
      else if (max < a + b) {
        max = a + b;
        maxchar = i;
      }
    }
    if (a == 0 && b == 0)
      break;
    cout << c[maxchar] << " " << max << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  while (1) {
    int max = -1;
    char c[5];
    c[0] = 'A';
    c[1] = 'B';
    c[2] = 'C';
    c[3] = 'D';
    c[4] = 'E';
    int maxchar = 0;

    for (int i = 0; i < 5; i++) {
      cin >> a >> b;
      if (a == 0 && b == 0)
        break;
      if (max < a + b) {
        max = a + b;
        maxchar = i;
      }
    }
    cout << c[maxchar] << " " << max << endl;
  }
}
Problem p00195 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#define buf 10000
using namespace std;
int B[10];
void BubbleSort(void);

int main(void) {
  int i, n, m, A[20001];
  char str[buf];

  for (;;) {
    for (i = 0; i < 5; i++) {
      fgets(str, sizeof(str), stdin);
      sscanf(str, "%d %d", &n, &m);
      if (n == 0 && m == 0)
        return 0;
      B[i] = n + m;
      A[n + m] = i;
    }
    BubbleSort();
    printf("%c %d\\n", 'A' + A[B[0]], B[0]);
  }
  return 0;
}

void BubbleSort(void) {
  int i, j, tmp;
  for (i = 0; i < 4; i++) {
    for (j = 4; j > i; j--) {
      if (B[j] > B[j - 1]) {
        tmp = B[j - 1];
        B[j - 1] = B[j];
        B[j] = tmp;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#define buf 10000
using namespace std;
int B[10];
void BubbleSort(void);

int main(void) {
  int i, n, m, A[20001];
  char str[buf];

  for (;;) {
    for (i = 0; i < 5; i++) {
      fgets(str, sizeof(str), stdin);
      sscanf(str, "%d %d", &n, &m);
      if (n == 0 && m == 0)
        break;
      B[i] = n + m;
      A[n + m] = i;
    }
    BubbleSort();
    printf("%c %d\\n", 'A' + A[B[0]], B[0]);
  }
  return 0;
}

void BubbleSort(void) {
  int i, j, tmp;
  for (i = 0; i < 4; i++) {
    for (j = 4; j > i; j--) {
      if (B[j] > B[j - 1]) {
        tmp = B[j - 1];
        B[j - 1] = B[j];
        B[j] = tmp;
      }
    }
  }
}
Problem p00195 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
int main(void) {
  int a[5], b[5], d, i, j;
  char c[6] = "ABCDE";
  scanf("%d %d", &a[0], &b[0]);
  while (a[0] != 0 && b[0] != 0) {
    j = 0;
    d = a[0] + b[0];
    for (i = 1; i < 5; i++) {
      scanf("%d %d", &a[i], &b[i]);
    }
    for (i = 0; i < 5; i++) {
      if (a[i] + b[i] > d) {
        d = a[i] + b[i];
        j = i;
      }
    }
    printf("%c %d\\n", c[j], d);
    scanf("%d %d", &a[0], &b[0]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
int main(void) {
  int a[5], b[5], d, i, j;
  char c[6] = "ABCDE";
  scanf("%d %d", &a[0], &b[0]);
  while (a[0] != 0 || b[0] != 0) {
    j = 0;
    d = a[0] + b[0];
    for (i = 1; i < 5; i++) {
      scanf("%d %d", &a[i], &b[i]);
      if (a[i] + b[i] > d) {
        d = a[i] + b[i];
        j = i;
      }
    }
    printf("%c %d\\n", c[j], d);
    scanf("% %d", &a[0], &b[0]);
  }
  return 0;
}
Problem p00195 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * File:   main.cpp
 * Author: freebsd
 *
 * Created on 2014/08/28, 10:07
 */

#include <cstdio>

using namespace std;

int main() {
  while (true) {
    int s1[5] = {0}, s2[5] = {0};

    char store[5] = {'A', 'B', 'C', 'D', 'E'};

    for (int i = 0; i < 5; i++) {
      scanf("%d %d", &s1[i], &s2[i]);
      if (s1[0] == 0 && s2[0] == 0)
        return 0;
    }

    for (int i = 0; i < 5; i++) {
      s1[i] += s2[i];
    }

    int i = 0;
    char tempc;
    int max;

    max = s1[0];
    tempc = store[0];

    while (i != 4) {

      if (max < s1[i + 1]) {
        max = s1[i + 1];
        tempc = store[i + 1];
      }
      i++;
    }

    printf("%c %d\\n", tempc, max);
  }
}

Error: TLE

Fixed submission:

/*
 * File:   main.cpp
 * Author: freebsd
 *
 * Created on 2014/08/28, 10:07
 */

#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  while (true) {
    int s1[5] = {0}, s2[5] = {0};

    char store[5] = {'A', 'B', 'C', 'D', 'E'};

    char result = 0;

    for (int i = 0; i < 5; i++) {
      scanf("%d %d", &s1[i], &s2[i]);
    }

    for (int i = 0; i < 5; i++) {
      s1[i] += s2[i];
    }

    int i = 0;
    int max;

    max = s1[i];

    while (true) {
      if (s1[i] < s1[i + 1])
        max = s1[i + 1];
      if ((i + 1) == 4)
        break;
    }

    result = store[i];

    printf("%c %d", result, max);
  }
}
Problem p00195 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  int best, set, s1, s2;
  bool t = true;
  while (true) {
    best = 0;
    for (int i = 0; i < 5; i++) {
      cin >> s1 >> s2;
      if (s1 == 0 && s2 == 0) {
        t = false;
        break;
      }
      if (best < s1 + s2) {
        set = i;
        best = s1 + s2;
      }
    }
    if (t == false)
      break;
    char z = 'A' + set;
    cout << z << " " << best << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int best, set, s1, s2;
  while (true) {
    best = 0;
    for (int i = 0; i < 5; i++) {
      cin >> s1 >> s2;
      if (s1 == 0 && s2 == 0)
        break;
      if (best < s1 + s2) {
        set = i;
        best = s1 + s2;
      }
    }
    char z = 'A' + set;
    cout << z << " " << best << endl;
  }
  return 0;
}
Problem p00195 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {

  while (1) {
    char c = 'A';
    int maxi = 0;
    bool flag = 0;
    rep(i, 5) {
      int a, b;
      cin >> a >> b;
      if (a == b && a == 0) {
        flag = 1;
        break;
      }
      if (maxi <= (a + b)) {
        maxi = a + b;
        c = 'A' + i;
      }
    }
    if (flag)
      break;
    cout << c << " " << maxi << endl;
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

Error: 1

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {

  while (1) {
    char c = 'A';
    int maxi = 0;
    rep(i, 5) {
      int a, b;
      cin >> a >> b;
      if (a == b && a == 0)
        exit(1);
      if (maxi <= (a + b)) {
        maxi = a + b;
        c = 'A' + i;
      }
    }
    cout << c << " " << maxi << endl;
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
Problem p00196 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int a[100000];
int n, sum, p;
char c[100000];
int main() {
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> c[i];
      sum = 0;
      for (int j = 0; j < n - 1; j++) {
        cin >> p;
        if (p == 0) {
          sum += 10000;
        }
        if (p == 2) {
          sum += 100;
        }
      }
      sum += (20 - i);
      a[i] = sum;
    }
    sort(a, a + n);
    for (int i = n - 1; i >= 0; i--) {
      cout << c[20 - (a[i] % 100)] << endl;
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
pair<int, string> a[100000];
int n, sum, p;
int main() {
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i].second;
      sum = 0;
      for (int j = 0; j < n - 1; j++) {
        cin >> p;
        if (p == 0) {
          sum += 10000;
        }
        if (p == 2) {
          sum += 1;
        }
      }
      a[i].first = sum;
    }
    sort(a, a + n);
    for (int i = n - 1; i >= 0; i++) {
      cout << a[i].second << endl;
    }
  }
}
Problem p00196 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  char ti[10000];
  int ho[10000];
  while (1) {
    int n, win[10000] = {}, lose[100000] = {}, blow[100000] = {};

    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> ti[i];
      for (int j = 0; j < n - 1; j++) {
        cin >> ho[j];
        if (ho[j] == 0)
          win[i] += 1;
        if (ho[j] == 1)
          lose[i] += 1;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j + 1 < n; j++) {
        if (win[j] < win[j + 1] ||
            (win[j] == win[j + 1] && lose[j] > lose[j + 1])) {
          swap(lose[j], lose[j + 1]);
          swap(win[j], win[j + 1]);
          swap(ti[j], ti[j + 1]);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << ti[i] << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  while (1) {
    int max = -1;
    char c[5];
    c[0] = 'A';
    c[1] = 'B';
    c[2] = 'C';
    c[3] = 'D';
    c[4] = 'E';
    int maxchar = 0;
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    for (int i = 0; i < 5; i++) {
      if (max < a + b) {
        max = a + b;
        maxchar = i;
      }
    }
    cout << c[maxchar] << " " << max << endl;
  }
}
Problem p00196 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 21)
bool cmp(const pair<int, char> &a, const pair<int, char> &b) {
  return a.first > b.first;
}

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<pair<int, char>> data(n);
    rep(i, n) {
      int sum = 0;
      cin >> data[i].second;
      rep(j, n - 1) {
        int t;
        cin >> t;
        sum += (t == 0 ? 10 : t == 2 ? 1 : 0);
      }
      data[i].first = sum;
    }
    stable_sort(data.begin(), data.end(), cmp);
    rep(i, n) { cout << data[i].second << endl; }
  }
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int main(void) {
  int a, b, n;
  char t[20];
  int w[10], l[10];
  while (1) {
    memset(t, 0, sizeof(w));
    memset(w, 0, sizeof(w));
    memset(l, 0, sizeof(l));
    cin >> n;
    if (n == 0)
      break;
    for (a = 0; a < n; a++) {
      cin >> t[a];
      for (b = 0; b < n - 1; b++) {
        int b;
        cin >> b;
        if (b == 0)
          w[a]++;
        if (b == 1)
          l[a]++;
      }
    }
    for (a = 0; a < n - 1; a++) {
      for (b = a + 1; b < n; b++) {
        if (w[b] > w[a] || w[b] == w[a] && l[b] < l[a])
          swap(t[a], t[b]), swap(w[a], w[b]), swap(l[a], l[b]);
      }
    }
    for (a = 0; a < n; a++) {
      cout << t[a] << endl;
    }
  }
  return 0;
}
Problem p00196 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int n, a;
pair<int, char> d[10];
int main() {
  while (true) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> d[i].second;
      d[i].first = i;
      for (int j = 0; j < n - 1; j++) {
        scanf("%d", &a);
        if (a == 0)
          d[i].first -= 100;
        if (a == 1)
          d[i].first += 10;
      }
    }
    sort(d, d + n);
    for (int i = 0; i < n; i++)
      printf("%c\\n", d[i].second);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n, a, d[10], e[10];
char c[10];
int main() {
  while (true) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> c[i];
      for (int j = 0; j < n; j++) {
        scanf("%d", &a);
        if (a == 0)
          d[i]++;
        if (a == 1)
          e[i]++;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (d[i] < d[j]) {
          swap(c[i], c[j]);
          swap(d[i], d[j]);
          swap(e[i], e[j]);
        } else if (d[i] == d[j] && e[i] > e[j]) {
          swap(c[i], c[j]);
          swap(d[i], d[j]);
          swap(e[i], e[j]);
        }
      }
    }
    for (int i = 0; i < n; i++)
      printf("%c\\n", c[i]);
  }
  return 0;
}
Problem p00196 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

void ins(vector<pair<int, pair<int, char>>> &a) {
  int s = a.size() - 1;
  if (s == 0)
    return;
  while (a[s].first > a[s - 1].first) {
    swap(a[s], a[s - 1]);
    s--;
    if (s == 0)
      break;
  }
  if (s == 0)
    return;
  while (a[s].first == a[s - 1].first &&
         a[s].second.first < a[s - 1].second.first) {
    swap(a[s], a[s - 1]);
    s--;
    if (s == 0)
      break;
  }
  return;
}

int main() {
  while (true) {
    int n;
    cin >> n;
    vector<pair<int, pair<int, char>>> ans;
    if (n == 0)
      break;
    REP(i, n) {
      char t;
      int temp;
      int w, l;
      w = 0;
      l = 0;
      cin >> t;
      REP(i, n - 1) {
        cin >> temp;
        if (temp == 0)
          w++;
        else if (temp == 1)
          l++;
      }
      ans.PB(pair<int, pair<int, char>>(w, pair<int, char>(l, t)));
      ins(ans);
    }
    REP(i, n) cout << ans[i].second.second << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

void ins(vector<pair<int, pair<int, char>>> &a) {
  int s = a.size() - 1;
  while (a[s].first < a[s - 1].first) {
    swap(a[s], a[s - 1]);
    s--;
    if (s == 0)
      break;
  }
  if (s == 0)
    return;
  while (a[s].first == a[s - 1].first &&
         a[s].second.first > a[s - 1].second.first) {
    swap(a[s], a[s - 1]);
    s--;
    if (s == 0)
      break;
  }
  return;
}

int main() {
  while (true) {
    int n;
    cin >> n;
    vector<pair<int, pair<int, char>>> ans;
    if (n == 0)
      break;
    REP(i, n) {
      char t;
      int temp;
      int w, l;
      w = 0;
      l = 0;
      cin >> t;
      REP(i, n - 1) {
        cin >> temp;
        if (temp == 0)
          w++;
        else if (temp == 1)
          l++;
      }
      ans.PB(pair<int, pair<int, char>>(w, pair<int, char>(l, t)));
      ins(ans);
    }
    sort(RALL(ans));
    REP(i, n) cout << ans[i].second.second << endl;
  }
  return 0;
}
Problem p00197 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  long long int a, b;
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    if (a < b)
      swap(a, b);
    int cnt = 0;
    while (1) {
      a %= b;
      swap(a, b);
      cnt++;
      if (b == 0)
        break;
    }
    cout << a << " " << cnt << endl;
  }
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int cnt;
int main() {
  long long int a, b;
  cnt = 0;
  while (1) {
    cin >> a >> b;
    if (a < b)
      swap(a, b);
    while (1) {
      a %= b;
      swap(a, b);
      cnt++;
      if (b == 0)
        break;
    }
    cout << a << " " << cnt << endl;
  }
}
Problem p00197 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  while (cin >> a >> b, a + b) {
    if (a < b)
      swap(a, b);
    int cnt = 0;
    while (1) {
      c = a % b;
      a = b;
      b = c;
      cnt++;
      if (c == 0)
        break;
    }
    cout << a << " " << cnt << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  while (cin >> a >> b) {
    if (a < b)
      swap(a, b);
    int cnt = 0;
    while (1) {
      c = a % b;
      a = b;
      b = c;
      cnt++;
      if (c == 0)
        break;
    }
    cout << a << " " << cnt << endl;
  }
}