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

Buggy submission (status: Runtime Error):

#include <stdio.h>
#include <string.h>

int board[1234][1234];
int mark[1234][1234];

int main() {
  for (;;) {
    int h, w, n;
    scanf("%d %d %d", &h, &w, &n);
    if (h == 0 && w == 0 && n == 0)
      break;
    memset(board, 255, sizeof(board));
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        scanf("%d", &board[i][j]);
      }
    }
    memset(mark, 0, sizeof(mark));
    mark[0][0] = n - 1;
    for (int sum = 0; sum < w + h - 1; ++sum) {
      for (int vr = 0; vr <= sum; ++vr) {
        int hr = sum - vr;
        if (hr >= w)
          continue;
        if (hr < 0)
          break;
        if (board[vr][hr] == 0) {
          mark[vr][hr + 1] += mark[vr][hr] / 2;
          mark[vr + 1][hr] += mark[vr][hr] / 2 + (mark[vr][hr] % 2);
        } else {
          mark[vr][hr + 1] += mark[vr][hr] / 2 + (mark[vr][hr] % 2);
          mark[vr + 1][hr] += mark[vr][hr] / 2;
        }
        if (mark[vr][hr] % 2) {
          board[vr][hr] = (board[vr][hr] == 0) ? 1 : 0;
        }
      }
    }
    int py = 0, px = 0;
    while (board[py][px] >= 0) {
      if (board[py][px] == 0) {
        ++py;
      } else {
        ++px;
      }
    }
    printf("%d %d\n", py + 1, px + 1);
  }
  return 0;
}

Fixed submission:

#include <stdio.h>
#include <string.h>

int board[1234][1234];
int mark[1234][1234];

int main() {
  for (;;) {
    int h, w, n;
    scanf("%d %d %d", &h, &w, &n);
    if (h == 0 && w == 0 && n == 0)
      break;
    memset(board, 255, sizeof(board));
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        scanf("%d", &board[i][j]);
      }
    }
    memset(mark, 0, sizeof(mark));
    mark[0][0] = n - 1;
    for (int sum = 0; sum < w + h - 1; ++sum) {
      for (int vr = 0; vr <= sum; ++vr) {
        if (vr >= h)
          break;
        int hr = sum - vr;
        if (hr >= w)
          continue;
        if (hr < 0)
          break;
        if (board[vr][hr] == 0) {
          mark[vr][hr + 1] += mark[vr][hr] / 2;
          mark[vr + 1][hr] += mark[vr][hr] / 2 + (mark[vr][hr] % 2);
        } else {
          mark[vr][hr + 1] += mark[vr][hr] / 2 + (mark[vr][hr] % 2);
          mark[vr + 1][hr] += mark[vr][hr] / 2;
        }
        if (mark[vr][hr] % 2) {
          board[vr][hr] = (board[vr][hr] == 0) ? 1 : 0;
        }
      }
    }
    int py = 0, px = 0;
    while (board[py][px] >= 0) {
      if (board[py][px] == 0) {
        ++py;
      } else {
        ++px;
      }
    }
    printf("%d %d\n", py + 1, px + 1);
  }
  return 0;
}
Problem p00464 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int h, w, n;
int a[1002][1002], b[1002][1002] = {0};

pair<int, int> walk(int x, int y) {
  if (a[x][y] == 0)
    x++;
  else
    y++;
  if (x < h && y < w)
    return walk(x, y);
  pair<int, int> ret;
  ret.first = x + 1;
  ret.second = y + 1;
  return ret;
}

int main() {
  while (1) {
    scanf("%d%d%d", &h, &w, &n);
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &a[i][j]);
        b[i][j] = 0;
      }
    }
    b[0][0] = n - 1;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        b[i][j + 1] += b[i][j] / 2;
        b[i + 1][j] += b[i][j] / 2;
        if (b[i][j] % 2 == 1) {
          if (a[i][j] == 0)
            b[i + 1][j]++;
          else
            b[i][j + 1]++;
        }
        a[i][j] += b[i][j];
        a[i][j] %= 2;
      }
    }
    pair<int, int> ret = walk(0, 0);
    printf("%d %d\n", ret.first, ret.second);
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int h, w, n;
int a[1002][1002], b[1002][1002] = {0};

pair<int, int> walk(int x, int y) {
  if (a[x][y] == 0)
    x++;
  else
    y++;
  if (x < h && y < w)
    return walk(x, y);
  pair<int, int> ret;
  ret.first = x + 1;
  ret.second = y + 1;
  return ret;
}

int main() {
  while (1) {
    scanf("%d%d%d", &h, &w, &n);
    if (h == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &a[i][j]);
        b[i][j] = 0;
      }
    }
    b[0][0] = n - 1;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        b[i][j + 1] += b[i][j] / 2;
        b[i + 1][j] += b[i][j] / 2;
        if (b[i][j] % 2 == 1) {
          if (a[i][j] == 0)
            b[i + 1][j]++;
          else
            b[i][j + 1]++;
        }
        a[i][j] += b[i][j];
        a[i][j] %= 2;
      }
    }
    pair<int, int> ret = walk(0, 0);
    printf("%d %d\n", ret.first, ret.second);
  }
}
Problem p00464 (C++)

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

int d[1005][1005];
bool e[1005][1005];
int a, b, c;
signed main() {
  while (cin >> a >> b >> c, a | b | c) {
    memset(d, 0, sizeof(d));
    memset(e, false, sizeof(e));
    for (int f = 0; f < a; f++) {
      for (int g = 0; g < b; g++) {
        scanf("%d", &e[f][g]);
      }
    }
    d[0][0] = c - 1;
    for (int h = 0; h < a + b - 1; h++) {
      for (int i = 0; i <= h; i++) {
        int x = i, y = h - i;
        if (d[x][y] & 1) {
          if (e[x][y]) {
            d[x + 1][y] += d[x][y] / 2;
            d[x][y + 1] += d[x][y] / 2 + 1;
          } else {
            d[x + 1][y] += d[x][y] / 2 + 1;
            d[x][y + 1] += d[x][y] / 2;
          }
        } else {
          d[x + 1][y] += d[x][y] / 2;
          d[x][y + 1] += d[x][y] / 2;
        }
        e[x][y] = (e[x][y] + d[x][y]) & 1;
      }
    }
    int x = 0, y = 0;
    while (1) {
      if (x == a || y == b) {
        cout << x + 1 << " " << y + 1 << endl;
        break;
      }
      if (e[x][y])
        y++;
      else
        x++;
    }
  }
}

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

int d[3005][3005];
bool e[3005][3005];
int a, b, c;
signed main() {
  while (cin >> a >> b >> c, a | b | c) {
    memset(d, 0, sizeof(d));
    memset(e, false, sizeof(e));
    for (int f = 0; f < a; f++) {
      for (int g = 0; g < b; g++) {
        scanf("%d", &e[f][g]);
      }
    }
    d[0][0] = c - 1;
    for (int h = 0; h < a + b - 1; h++) {
      for (int i = 0; i <= h; i++) {
        int x = i, y = h - i;
        if (d[x][y] & 1) {
          if (e[x][y]) {
            d[x + 1][y] += d[x][y] / 2;
            d[x][y + 1] += d[x][y] / 2 + 1;
          } else {
            d[x + 1][y] += d[x][y] / 2 + 1;
            d[x][y + 1] += d[x][y] / 2;
          }
        } else {
          d[x + 1][y] += d[x][y] / 2;
          d[x][y + 1] += d[x][y] / 2;
        }
        e[x][y] = (e[x][y] + d[x][y]) & 1;
      }
    }
    int x = 0, y = 0;
    while (1) {
      if (x == a || y == b) {
        cout << x + 1 << " " << y + 1 << endl;
        break;
      }
      if (e[x][y])
        y++;
      else
        x++;
    }
  }
}
Problem p00464 (C++)

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

#define MAX_N 2000

long long x[MAX_N][MAX_N];
long long dp[MAX_N][MAX_N];
int h, w, n, cx, cy;
int main() {
  while (true) {
    memset(dp, 0, sizeof(dp));
    cin >> h >> w >> n;
    if (h == 0 && w == 0 && n == 0) {
      break;
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        scanf("%d", x[i][j]);
      }
    }
    dp[1][1] = n - 1;
    for (int i = 2; i <= h + w; i++) {
      for (int j = 1; j <= h; j++) {
        int k = i - j;
        if (k >= 1 && k <= w) {
          if (x[j][k] == 0) {
            dp[j][k + 1] += dp[j][k] / 2;
            dp[j + 1][k] += (dp[j][k] + 1) / 2;
          } else {
            dp[j][k + 1] += (dp[j][k] + 1) / 2;
            dp[j + 1][k] += dp[j][k] / 2;
          }
        }
      }
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        x[i][j] += dp[i][j];
        x[i][j] %= 2;
      }
    }
    cx = 1;
    cy = 1;
    while (cx <= w && cy <= h) {
      if (x[cy][cx] == 0) {
        cy++;
      } else {
        cx++;
      }
    }
    cout << cy << ' ' << cx << endl;
  }
  return 0;
}

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

#define MAX_N 2000

long long x[MAX_N][MAX_N];
long long dp[MAX_N][MAX_N];
int h, w, n, cx, cy;
int main() {
  while (true) {
    memset(dp, 0, sizeof(dp));
    cin >> h >> w >> n;
    if (h == 0 && w == 0 && n == 0) {
      break;
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        scanf("%d", &x[i][j]);
      }
    }
    dp[1][1] = n - 1;
    for (int i = 2; i <= h + w; i++) {
      for (int j = 1; j <= h; j++) {
        int k = i - j;
        if (k >= 1 && k <= w) {
          if (x[j][k] == 0) {
            dp[j][k + 1] += dp[j][k] / 2;
            dp[j + 1][k] += (dp[j][k] + 1) / 2;
          } else {
            dp[j][k + 1] += (dp[j][k] + 1) / 2;
            dp[j + 1][k] += dp[j][k] / 2;
          }
        }
      }
    }
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        x[i][j] += dp[i][j];
        x[i][j] %= 2;
      }
    }
    cx = 1;
    cy = 1;
    while (cx <= w && cy <= h) {
      if (x[cy][cx] == 0) {
        cy++;
      } else {
        cx++;
      }
    }
    cout << cy << ' ' << cx << endl;
  }
  return 0;
}
Problem p00465 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <queue>
#include <stdio.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, b) FOR(i, 0, b)

struct cxy {
  int cost, x, y;
  bool operator<(const cxy &rhs) const { return cost < rhs.cost; }
  bool operator>(const cxy &rhs) const { return cost > rhs.cost; }
};

int CalcTable(int *ret) {
  int w, h, x, y;
  scanf("%d%d%d%d", &w, &h, &x, &y);
  static int m[500][500];
  REP(i, h)
  REP(j, w)
  scanf("%d", &m[i][j]);
  ret[0] = 0;
  priority_queue<cxy, vector<cxy>, greater<cxy>> pq;
  static bool used[500][500];
  REP(i, h)
  REP(j, w)
  used[i][j] = false;
  pq.push({1, --x, --y});
  used[y][x] = true;
  int c = 0;
  static const int dxy[] = {0, -1, 0, 1, 0};
  int b = 0;
  while (!pq.empty()) {
    cxy t = pq.top();
    pq.pop();
    b = max(b, t.cost);
    ret[++c] = b;
    REP(i, 4) {
      int nx = t.x + dxy[i];
      int ny = t.y + dxy[i + 1];
      if (0 <= nx && nx < w && 0 <= ny && ny < h)
        if (!used[ny][nx]) {
          pq.push({m[ny][nx], nx, ny});
          used[ny][nx] = true;
        }
    }
  }
  return w * h + 1;
}

int main() {
  while (1) {
    int r;
    scanf("%d", &r);
    if (r == 0)
      break;
    static int buf1[250001];
    static int buf2[250001];
    int r1 = CalcTable(buf1);
    int r2 = CalcTable(buf2);
    int ans = 1145141919;
    REP(i, r1) {
      int j = r - i;
      if (j < r2)
        ans = min(ans, buf1[i] + buf2[j]);
    }
    printf("%d\n", ans);
  }
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <queue>
#include <stdio.h>

using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, b) FOR(i, 0, b)

struct cxy {
  int cost, x, y;
  bool operator<(const cxy &rhs) const { return cost < rhs.cost; }
  bool operator>(const cxy &rhs) const { return cost > rhs.cost; }
};

int CalcTable(int *ret) {
  int w, h, x, y;
  scanf("%d%d%d%d", &w, &h, &x, &y);
  static int m[500][500];
  REP(i, h)
  REP(j, w)
  scanf("%d", &m[i][j]);
  ret[0] = 0;
  priority_queue<cxy, vector<cxy>, greater<cxy>> pq;
  static bool used[500][500];
  REP(i, h)
  REP(j, w)
  used[i][j] = false;
  pq.push({1, --x, --y});
  used[y][x] = true;
  int c = 0;
  static const int dxy[] = {0, -1, 0, 1, 0};
  int b = 0;
  while (!pq.empty()) {
    cxy t = pq.top();
    pq.pop();
    b = max(b, t.cost);
    ret[++c] = b;
    REP(i, 4) {
      int nx = t.x + dxy[i];
      int ny = t.y + dxy[i + 1];
      if (0 <= nx && nx < w && 0 <= ny && ny < h)
        if (!used[ny][nx]) {
          pq.push({m[ny][nx], nx, ny});
          used[ny][nx] = true;
        }
    }
  }
  return w * h + 1;
}

int main() {
  while (1) {
    int r;
    scanf("%d", &r);
    if (r == 0)
      break;
    static int buf1[250001];
    static int buf2[250001];
    int r1 = CalcTable(buf1);
    int r2 = CalcTable(buf2);
    int ans = 1145141919;
    REP(i, r1) {
      int j = r - i;
      if (0 <= j && j < r2)
        ans = min(ans, buf1[i] + buf2[j]);
    }
    printf("%d\n", ans);
  }
}
Problem p00465 (C++)

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

using namespace std;

typedef pair<int, pair<int, int>> pp;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int level[2][100001];
int room[500][500];
bool visited[500][500];

int main() {
  int r;
  while (cin >> r, r) {
    int w, h, ex, ey;
    int e[2];
    for (int i = 0; i < 2; ++i) {
      cin >> w >> h >> ex >> ey;
      for (int j = 0; j < h; ++j) {
        for (int k = 0; k < w; ++k) {
          cin >> room[j][k];
        }
      }
      memset(visited, 0, sizeof(visited));
      visited[--ey][--ex] = 1;
      level[i][0] = 0;
      int mlevel = 0, index = 1;
      priority_queue<pp, vector<pp>, greater<pp>> pq;
      pq.push(make_pair(room[ey][ex], make_pair(ex, ey)));
      while (!pq.empty()) {
        pp cur = pq.top();
        pq.pop();
        mlevel = max(mlevel, cur.first);
        level[i][index++] = mlevel;
        for (int j = 0; j < 4; ++j) {
          int cx = cur.second.first + dx[j];
          int cy = cur.second.second + dy[j];
          if (cx >= 0 && cx < w && cy >= 0 && cy < h && visited[cy][cx] == 0) {
            visited[cy][cx] = 1;
            pq.push(make_pair(room[cy][cx], make_pair(cx, cy)));
          }
        }
      }
      e[i] = index - 1;
    }
    int ans = 1000000000;
    for (int i = 0; i <= r; ++i) {
      if (e[0] < r - i || e[1] < i)
        continue;
      ans = min(ans, level[1][i] + level[0][r - i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, pair<int, int>> pp;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int level[2][250001];
int room[500][500];
bool visited[500][500];

int main() {
  int r;
  while (cin >> r, r) {
    int w, h, ex, ey;
    int e[2];
    for (int i = 0; i < 2; ++i) {
      cin >> w >> h >> ex >> ey;
      for (int j = 0; j < h; ++j) {
        for (int k = 0; k < w; ++k) {
          cin >> room[j][k];
        }
      }
      memset(visited, 0, sizeof(visited));
      visited[--ey][--ex] = 1;
      level[i][0] = 0;
      int mlevel = 0, index = 1;
      priority_queue<pp, vector<pp>, greater<pp>> pq;
      pq.push(make_pair(room[ey][ex], make_pair(ex, ey)));
      while (!pq.empty()) {
        pp cur = pq.top();
        pq.pop();
        mlevel = max(mlevel, cur.first);
        level[i][index++] = mlevel;
        for (int j = 0; j < 4; ++j) {
          int cx = cur.second.first + dx[j];
          int cy = cur.second.second + dy[j];
          if (cx >= 0 && cx < w && cy >= 0 && cy < h && visited[cy][cx] == 0) {
            visited[cy][cx] = 1;
            pq.push(make_pair(room[cy][cx], make_pair(cx, cy)));
          }
        }
      }
      e[i] = index - 1;
    }
    int ans = 1000000000;
    for (int i = 0; i <= r; ++i) {
      if (e[0] < r - i || e[1] < i)
        continue;
      ans = min(ans, level[1][i] + level[0][r - i]);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>

using namespace std;
int main(void) {
  int a, b;
  while (scanf("%d", &a) != 0) {
    int c = 0;
    for (int i = 1; i < 10; i++) {
      scanf("%d", &b);
      c += b;
    }
    c = a - c;
    printf("%d\n", c);
  }
  return 0;
}

Fixed submission:
#include <cstdio>

using namespace std;
int main(void) {
  int a, b;
  while (scanf("%d", &a)) {
    if (a == 0)
      break;
    int c = 0;
    for (int i = 1; i < 10; i++) {
      scanf("%d", &b);
      c += b;
    }
    c = a - c;
    printf("%d\n", c);
  }
  return 0;
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int a, b, c, d;
    cin >> a;
    if (a == 0) {
      break;
    }
    d = 0;
    for (b = 0; b < 10; b++) {
      cin >> c;
      d = d + c;
    }
    b = a - d;
    cout << b << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int a, b, c, d;
    cin >> a;
    if (a == 0) {
      break;
    }
    d = 0;
    for (b = 0; b < 9; b++) {
      cin >> c;
      d = d + c;
    }
    b = a - d;
    cout << b << endl;
  }
  return 0;
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  while (1) {
    int n;
    int a;
    int sum = 0;
    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < 10; i++) {
      cin >> a;
      sum += a;
    }
    a = n - sum;

    cout << a << endl;
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  while (1) {
    int n;
    int a;
    int sum = 0;
    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < 9; i++) {
      cin >> a;
      sum += a;
    }
    a = n - sum;

    cout << a << endl;
  }

  return 0;
}
Problem p00466 (C++)

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

using namespace std;

int main() {
  int sum = 0, in;
  while (cin >> sum, sum) {
    for (int i = 0; i < 10; i++) {
      cin >> in;
      sum -= in;
    }
    cout << sum << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int sum = 0, in;
  while (cin >> sum, sum) {
    for (int i = 0; i < 9; i++) {
      cin >> in;
      sum -= in;
    }
    cout << sum << endl;
  }
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b, n = 1, i = 0;
  cin >> a;
  do {
    if (a > 10000) {
      break;
    }
    cin >> b;
    a = a - b;
    i++;
    if (i = 9 * n) {
      cout << a << endl;
      n++;
    }
  } while (i <= 9 * n);

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int total;
  cin >> total;
  while (total != 0) {
    int a, b, c, d, e, f, g, h, i, j;
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
    j = total - (a + b + c + d + e + f + g + h + i);
    cout << j << endl;
    cin >> total;
  }
  return 0;
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int total;
  int books;
  int count = 0;

  while (true) {
    if (count == 0) {
      cin >> total;
      if (total == 0) {
        break;
      }
      count++;
    } else {
      cin >> books;
      total -= books;
      count++;
    }
    if (count == 10) {
      cout << total << '\n';
    }
  }
  return 0;
}

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

int main() {
  int total;
  int books;
  int count = 0;

  while (true) {
    if (count == 0) {
      cin >> total;
      if (total == 0) {
        break;
      }
      count++;
    } else {
      cin >> books;
      total -= books;
      count++;
    }
    if (count == 10) {
      cout << total << '\n';
      count = 0;
    }
  }
  return 0;
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  int n;
  while (cin >> n, n) {
    int t;
    rep(i, 10) {
      cin >> t;
      n -= t;
    }
    cout << n << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  int n;
  while (cin >> n, n) {
    int t;
    rep(i, 9) {
      cin >> t;
      n -= t;
    }
    cout << n << endl;
  }
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  while (1) {
    int ruio = 0;
    for (int i = 0; i < 9; i++) {
      cin >> b;
      ruio += b;
    }
    cout << a - ruio << endl;
    cin >> a;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  while (a != 0) {
    int ruio = 0;
    for (int i = 0; i < 9; i++) {
      cin >> b;
      ruio += b;
    }
    cout << a - ruio << endl;
    cin >> a;
  }
}
Problem p00466 (C++)

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

int main() {
  int s, a;
  while (cin >> s, s) {
    cin >> s;
    for (int i = 0; i < 9; i++) {
      cin >> a;
      s -= a;
    }
    cout << s << endl;
  }
}

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

int main() {
  int s, a;
  while (cin >> s) {
    if (s == 0)
      break;
    for (int i = 0; i < 9; i++) {
      cin >> a;
      s -= a;
    }
    cout << s << endl;
  }
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int total;
  cin >> total;
  int a, b, c, d, e, f, g, h, i, j;
  while (total != 0) {
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j;
    j = total - (a + b + c + d + e + f + g + h + i);
    cout << j << '\n';
    cin >> total;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int total;
  cin >> total;
  int a, b, c, d, e, f, g, h, i, j;
  while (total != 0) {
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
    j = total - (a + b + c + d + e + f + g + h + i);
    cout << j << '\n';
    cin >> total;
  }
  return 0;
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
using namespace std;
int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < 9; i++) {
      int c;
      scanf("%d", &c);
      n -= c;
    }
    printf("%d\n", n);
  }
}

Fixed submission:
#include <cstdio>
using namespace std;
int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < 9; i++) {
      int c;
      scanf("%d", &c);
      n -= c;
    }
    printf("%d\n", n);
  }
}
Problem p00466 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {

  int sum;
  int value[9];

  while (cin >> sum || sum) {
    for (int i = 0; i < 9; i++) {
      cin >> value[i];
      sum -= value[i];
    }
    cout << sum << endl;
  }

  return 0;
}

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

int main() {

  int sum;
  int value[9];

  while (cin >> sum, sum) {
    for (int i = 0; i < 9; i++) {
      cin >> value[i];
      sum -= value[i];
    }
    cout << sum << endl;
  }

  return 0;
}
Problem p00467 (C++)

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

using namespace std;
int main() {
  int masu[4000], n, m, iti, f;
  while (cin >> n >> m) {
    if (n == 0) {
      break;
    }
    iti = f = 1;
    for (int i = 1; i <= n + m; i++) {
      cin >> masu[i];
      if (i > n) {
        iti += masu[i];
        iti += masu[iti];
        if (iti >= n && f == 1) {
          printf("%d\n", i - n);
          f = 0;
        }
      }
    }
  }
}

Fixed submission:
#include <cstdio>
#include <iostream>

using namespace std;
int main() {
  int masu[9000], n, m, iti, f;
  while (cin >> n >> m) {
    if (n == 0) {
      break;
    }
    iti = f = 1;
    for (int i = 1; i <= n + m; i++) {
      cin >> masu[i];
      if (i > n) {
        iti += masu[i];
        iti += masu[iti];
        if (iti >= n && f == 1) {
          printf("%d\n", i - n);
          f = 0;
        }
      }
    }
  }
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int s[9000], n, m, t, f, i;
  while (scanf("%d%d", &n, &m), n)
    for (i = t = f = 1; i <= n + m | scanf("%d", &s[i]); i++) {
      ;
      if (i > n)
        if (t += s[t += s[i]], t >= n & f == 1)
          printf("%d\n", i - n, f = 0);
    }
}

Fixed submission:
#include <stdio.h>
int main() {
  int s[9000], n, m, t, f, i;
  while (scanf("%d%d", &n, &m), n)
    for (i = t = f = 1; i <= n + m; i++) {
      scanf("%d", &s[i]);
      if (i > n)
        if (t += s[t += s[i]], t >= n & f == 1)
          printf("%d\n", i - n, f = 0);
    }
}
Problem p00467 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  while (n != 0 && m != 0) {
    int date[1024];
    memset(date, 0, sizeof(date));
    for (int i = 0; i < n; ++i) {
      cin >> date[i];
    }
    int me;
    int point = 0;
    int ans;
    bool flg = true;
    for (int i = 0; i < m; ++i) {
      cin >> me;
      if (flg) {
        point += me;
        point += date[point];
        if (point >= n - 1) {
          ans = i + 1;
          flg = false;
        }
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  int n, m;

  while (cin >> n >> m && n != 0 && m != 0) {
    int date[1024];
    memset(date, 0, sizeof(date));
    for (int i = 0; i < n; ++i) {
      cin >> date[i];
    }
    int me;
    int point = 0;
    int ans;
    bool flg = true;
    for (int i = 0; i < m; ++i) {
      cin >> me;
      if (flg) {
        point += me;
        point += date[point];
        if (point >= n - 1) {
          ans = i + 1;
          flg = false;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, a) for (i = 0; i < a; i++)
using namespace std;
int main(void) {
  int n, m, d, i, cnt = 0, now = 0, flag = 0, x[3001] = {0};

  cin >> n >> m;
  while (n != 0 && m != 0) {
    fo(i, n) cin >> x[i];
    i = 0;
    fo(i, m) {
      cin >> d;
      now += d + x[now + d];
      if (flag == 0)
        cnt++;
      if (now >= n)
        flag = 1;
    }
    cout << cnt << endl;
    cnt = 0;
    now = 0;
    flag = 0;
    cin >> n >> m;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fo(i, a) for (i = 0; i < a; i++)
using namespace std;
int main(void) {
  int n, m, d, i, cnt = 0, now = 0, flag = 0, x[3001] = {0};

  cin >> n >> m;
  while (n != 0 && m != 0) {
    fo(i, n) cin >> x[i];
    i = 0;
    fo(i, m) {
      cin >> d;
      now += d + x[now + d];

      now = now > 1000 ? 1000 : now;

      if (flag == 0)
        cnt++;
      if (now >= n)
        flag = 1;
    }
    cout << cnt << endl;
    cnt = 0;
    now = 0;
    flag = 0;
    cin >> n >> m;
  }

  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int n, m, l[1024] = {0}, i, x, p, a;
  while (1) {
    scanf("%d%d", &n, &m);
    p = 0;
    a = 0;
    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < 1024; i++) {
      l[i] = 0;
    }

    for (i = 0; i < n; i++) {
      scanf("%d", &l[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &x);
      p += x + l[p + x];
      if (p >= n - 1 && a == 0) {
        a = i + 1;
      }
    }
    printf("%d\n", a);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int n, m, l[10000], i, x, p, a;
  while (1) {
    scanf("%d%d", &n, &m);
    p = 0;
    a = 0;
    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < 1024; i++) {
      l[i] = 0;
    }

    for (i = 0; i < n; i++) {
      scanf("%d", &l[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &x);
      p += x + l[p + x];
      if (p >= n - 1 && a == 0) {
        a = i + 1;
      }
    }
    printf("%d\n", a);
  }
  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int t[2000], n, m, a, ans, pos;
void init() {
  for (int i = 0; i < 2000; i++)
    t[i] = 0;
}
int main() {
  while (cin >> n >> m && n && m) {
    init();
    for (int i = 0; i < n; i++)
      cin >> t[i];
    ans = -1, pos = 0;
    for (int i = 0; i < m; i++) {
      cin >> a;
      pos += a;
      if (pos >= n - 1 && ans == -1)
        ans = i + 1;
      pos += t[pos];
      if (pos >= n - 1 && ans == -1)
        ans = i + 1;
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int t[2000], n, m, a, ans, pos;
void init() {
  for (int i = 0; i < 2000; i++)
    t[i] = 0;
}
int main() {
  while (cin >> n >> m && n && m) {
    init();
    for (int i = 0; i < n; i++)
      cin >> t[i];
    ans = -1, pos = 0;
    for (int i = 0; i < m; i++) {
      cin >> a;
      if (ans == -1) {
        pos += a;
        if (pos >= n - 1 && ans == -1)
          ans = i + 1;
        pos += t[pos];
        if (pos >= n - 1 && ans == -1)
          ans = i + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00467 (C++)

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

using namespace std;

int main(void) {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0)
      break;
    int mas[n], me[m];
    for (int i = 0; i < n; i++)
      scanf("%d", &mas[i]);
    for (int i = 0; i < m; i++)
      scanf("%d", &me[i]);
    int pos = 1, step = 0;
    while (pos < n) {
      pos = max(0, me[step] + mas[pos + me[step]]);
      step++;
    }
    printf("%d\n", step);
  }

  return 0;
}

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

using namespace std;

int main(void) {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0)
      break;
    int mas[n], me[m];
    for (int i = 0; i < n; i++)
      scanf("%d", &mas[i]);
    for (int i = 0; i < m; i++)
      scanf("%d", &me[i]);
    int pos = 1, step = 0;
    while (pos < n) {
      pos = max(1, pos + me[step] + mas[pos + me[step] - 1]);
      step++;
    }
    printf("%d\n", step);
  }

  return 0;
}
Problem p00467 (C++)

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

int main() {
  int n, m;
  int ms[MAX + 1];

  while (true) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (int i = 0; i < n; i++)
      cin >> ms[i];

    int go, t = 0, cnt = 0;
    bool flg = false;

    for (int i = 0; i < m; i++) {
      cin >> go;
      if (!flg) {
        t += go;
        t += ms[t];
        cnt++;
        if (t >= n - 1)
          flg = true;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

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

int main() {
  int n, m;
  int ms[MAX + 1];

  while (true) {
    cin >> n >> m;
    if (!n && !m)
      break;

    for (int i = 0; i < n; i++)
      cin >> ms[i];

    int go, t = 0, cnt = 0;
    bool flg = false;

    for (int i = 0; i < m; i++) {
      cin >> go;
      if (!flg) {
        t += go;
        t += ms[t];
        cnt++;
        if (t >= n - 1)
          flg = true;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int ans = -1, x = 0, face[1005];
    rep(i, n) cin >> face[i];
    rep(j, m) {
      int inp;
      cin >> inp;
      x += inp;
      x += face[x];
      if (x >= n - 1 && ans == -1) {
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int ans = -1, x = 0, face[1005];
    rep(i, n) cin >> face[i];
    rep(j, m) {
      int inp;
      cin >> inp;
      x += inp;
      x = min(x, n - 1);
      x += face[x];
      if (x >= n - 1 && ans == -1) {
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}
Problem p00467 (C++)

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

int main() {
  int pos = 0;
  int n, m;
  int cnt = 0;
  while (cin >> n >> m, n) {
    int array[n];
    cnt = 0;
    pos = 0;
    for (int i = 0; i < n; i++) {
      cin >> array[i];
    }
    for (int i = 0; i < m; i++) {
      int tmp;
      cin >> tmp;
      if (pos < n) {
        pos += tmp;
        pos += array[pos];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

int main() {
  int pos = 0;
  int n, m;
  int cnt = 0;
  int array[n];
  while (cin >> n >> m) {
    if (n == 0)
      break;
    cnt = 0;
    pos = 0;
    for (int i = 0; i < n; i++) {
      cin >> array[i];
    }
    for (int i = 0; i < m; i++) {
      int tmp;
      cin >> tmp;
      if (pos < n) {
        pos += tmp;
        pos += array[pos];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    if (a + b == 0)
      break;
    int m[a], w = 0, o[b], c = 0;
    r(i, a) cin >> m[i];
    r(i, b) cin >> o[i];
    r(i, b) {
      c++;
      w += o[i];
      w += m[w];
      if (w >= a)
        break;
    }
    cout << c << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    if (a + b == 0)
      break;
    int m[1100], w = 0, o[1100], c = 0;
    r(i, a) cin >> m[i];
    r(i, b) cin >> o[i];
    r(i, b) {
      c++;
      w += o[i];
      w += m[w];
      if (w >= a)
        break;
    }
    cout << c << endl;
  }
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int sugoroku[1010];

int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i;
    for (i = 1; i <= n; i++) {
      cin >> sugoroku[i];
    }
    int nw = 1;
    int res = -1;
    for (i = 1; i <= m; i++) {
      nw += in();
      if (nw >= n && res == -1)
        res = i;
      nw += sugoroku[nw];
      if (nw >= n && res == -1)
        res = i;
    }
    cout << res << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int sugoroku[1010];

int main() {
  int n, m;
  while (n = in(), m = in()) {
    int i;
    for (i = 1; i <= n; i++) {
      cin >> sugoroku[i];
    }
    int nw = 1;
    int res = -1;
    for (i = 1; i <= m; i++) {
      if (res == -1) {
        nw += in();
        if (nw >= n && res == -1) {
          res = i;
          continue;
        }
        nw += sugoroku[nw];
        if (nw >= n && res == -1)
          res = i;
      } else
        in();
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int n, m, c, g, a[10000];
int main() {
  while (true) {
    cin >> n >> m;
    c = 1;
    g = 0;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= m; i++) {
      int p;
      cin >> p;
      c += p;
      c += a[c];
      if (c >= n && g == 0) {
        g = i;
      }
    }
    cout << g << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int n, m, c, g, a[10000];
int main() {
  while (true) {
    cin >> n >> m;
    c = 1;
    g = 0;
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= m; i++) {
      int p;
      cin >> p;
      c += p;
      c += a[c];
      if (c >= n && g == 0) {
        g = i;
      }
    }
    cout << g << endl;
  }
  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  while (1) {
    int n, m;
    int now = 1;
    int field[110] = {0}, sai[110] = {0};
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++) {
      cin >> field[i];
    }
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
      cin >> sai[i];
    }
    for (int i = 1; i <= m; i++) {
      now += sai[i];
      now += field[now];
      cnt++;
      if (now >= n)
        break;
    }
    cout << cnt << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  while (1) {
    int n, m;
    int now = 1;
    int field[1010] = {0}, sai[1010] = {0};
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 1; i <= n; i++) {
      cin >> field[i];
    }
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
      cin >> sai[i];
    }
    for (int i = 1; i <= m; i++) {
      now += sai[i];
      now += field[now];
      cnt++;
      if (now >= n)
        break;
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define MAX 2048
using namespace std;
int main() {
  while (true) {
    int ans = 0;
    int pos = 0;
    int n, m;
    int sg[MAX];
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &sg[i]);
    }
    bool end = false;
    for (int i = 0; i < m; ++i) {
      int t;
      scanf("%d", &t);
      pos += t;
      if (!end && pos >= n) {
        ans = i + 1;
        end = true;
      }
      pos += sg[pos];
      // cout << pos << endl;
      if (!end && pos == n - 1) {
        ans = i + 1;
        end = true;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <iostream>
#define MAX 2048
using namespace std;
int main() {
  while (true) {
    int ans = 0;
    int pos = 0;
    int n, m;
    int sg[MAX];
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &sg[i]);
    }
    bool end = false;
    for (int i = 0; i < m; ++i) {
      int t;
      scanf("%d", &t);
      pos += t;
      if (pos >= n - 1) {
        if (!end) {
          ans = i + 1;
          end = true;
        }
        continue;
      } else {
        pos += sg[pos];
        if (!end && pos >= n - 1) {
          ans = i + 1;
          end = true;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
Problem p00467 (C++)

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

using namespace std;

#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for (int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int N, M;
int field[2000], dice;

int main() {
  while (scanf("%d %d", &N, &M), N || M) {
    int now = 0;
    rep(i, N) scanf("%d", &field[i]);
    int ans;
    bool flag = false;
    rep(i, M) {
      scanf("%d", &dice);
      now = now + dice;
      now = now + field[now];
      if (now < 0)
        now = 0;
      if (!flag) {
        if (now >= N)
          flag = true;
        ans = i;
      }
    }
    printf("%d\n", ans + 1);
  }
  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for (int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int N, M;
int field[10000], dice;

int main() {
  while (scanf("%d %d", &N, &M), N || M) {
    int now = 0;
    rep(i, N) scanf("%d", &field[i]);
    int ans;
    bool flag = false;
    rep(i, M) {
      scanf("%d", &dice);
      now = now + dice;
      now = now + field[now];
      if (now < 0)
        now = 0;
      if (!flag) {
        if (now >= N)
          flag = true;
        ans = i;
      }
    }
    printf("%d\n", ans + 1);
  }
  return 0;
}
Problem p00467 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int sugoroku[n + 1000];
    fill_n(sugoroku, n + 1000, 0);
    for (int i = 0; i < n; i++)
      cin >> sugoroku[i];
    int now = 1;
    int ans = -1;
    int flag = true;
    for (int i = 0; i < m; i++) {
      int me;
      cin >> me;
      now = now + me + sugoroku[now + me - 1];
      // cout<<now<<endl;
      if (now < 0)
        now = 0;
      if (now >= n && flag) {
        ans = i + 1;
        flag = false;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int sugoroku[n + 1000];
    fill_n(sugoroku, n + 1000, 0);
    for (int i = 0; i < n; i++)
      cin >> sugoroku[i];
    int now = 1;
    int ans = -1;
    int flag = true;
    for (int i = 0; i < m; i++) {
      int me;
      cin >> me;
      if (flag)
        now = now + me + sugoroku[now + me - 1];
      // cout<<now<<endl;
      if (now < 0)
        now = 0;
      if (now >= n && flag) {
        ans = i + 1;
        flag = false;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00467 (C++)

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

int main() {
  while (true) {
    int m = 0, n = 0, move[1000] = {}, turn = 0, flag = 0;
    double masu[1000] = {};
    cin >> m >> n;
    if (n == 0 || m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> masu[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> move[i];
    }
    for (int i = 0; i < n; i++) {
      flag = flag + move[i];
      flag = flag + masu[flag];
      turn++;
      if (flag == m)
        break;
    }
    cout << turn << endl;
  }
  return 0;
}

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

int main() {
  while (true) {
    int m = 0, n = 0, move[1000] = {}, turn = 0, flag = 0;
    double masu[1000] = {};
    cin >> m >> n;
    if (n == 0 || m == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> masu[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> move[i];
    }
    for (int i = 0; i < n; i++) {
      flag = flag + move[i];
      flag = flag + masu[flag];
      turn++;
      if (flag >= m)
        break;
    }
    cout << turn << endl;
  }
  return 0;
}
Problem p00468 (C++)

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

#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)

int main() {
  int n, m;
  pair<int, int> p[512];
  while (scanf("%d%d", &n, &m), n | m) {
    set<int> st1, st2;
    st1.insert(1);
    rep(i, m) {
      cin >> p[i].first >> p[i].second;
      if (p[i].first == 1 || p[i].second == 1) {
        st1.insert(p[i].first);
        st1.insert(p[i].second);
      }
    }
    rep(i, m) {
      if (st1.find(p[i].first) != st1.end() &&
          st1.find(p[i].second) == st1.end()) {
        st2.insert(p[i].second);
      }
      if (st1.find(p[i].second) != st1.end() &&
          st1.find(p[i].first) == st1.end()) {
        st2.insert(p[i].first);
      }
    }

    cout << (st1.size() - 1) + (st2.size()) << endl;
  }
  return 0;
}

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

#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)

int main() {
  int n, m;
  pair<int, int> p[10010];
  while (cin >> n >> m, n | m) {
    set<int> st1, st2;
    st1.insert(1);
    rep(i, m) {
      cin >> p[i].first >> p[i].second;
      if (p[i].first == 1 || p[i].second == 1) {
        st1.insert(p[i].first);
        st1.insert(p[i].second);
      }
    }
    rep(i, m) {
      if (st1.find(p[i].first) != st1.end() &&
          st1.find(p[i].second) == st1.end()) {
        st2.insert(p[i].second);
      }
      if (st1.find(p[i].second) != st1.end() &&
          st1.find(p[i].first) == st1.end()) {
        st2.insert(p[i].first);
      }
    }

    cout << (st1.size() - 1) + (st2.size()) << endl;
  }
  return 0;
}