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

#include <iostream>

int main() {

  int sum = 0, book[9] = {};
  const int f = 5;

  while (f == 5) {

    std::cin >> sum;

    if (sum == 0) {
      goto chin;
    }

    for (int i = 0; i < 9; i++) {
      std::cin >> book[i];
    }
    for (int j = 0; j < 9; j++) {
      sum = sum - book[j];
    }
    std::cout << sum << std::endl;
  }
chin:
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {

  int sum = 1, book[9] = {};

  while (sum != 0) {

    std::cin >> sum;

    for (int i = 0; i < 9; i++) {
      std::cin >> book[i];
    }
    for (int j = 0; j < 9; j++) {
      sum = sum - book[j];
    }
    std::cout << sum << std::endl;
  }

  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#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);
  }
}

Error: TLE

Fixed submission:

#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);
  }
}
Problem p00466 (C++) — buggy submission, verdict: 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;
}

Error: TLE

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 p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p00466 (C++) — buggy submission, verdict: 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 < 9; i++) {
      cin >> a;
      sum += a;
    }
    a = n - sum;

    cout << a << endl;
  }

  return 0;
}

Error: TLE

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 < 10; i++) {
      cin >> a;
      sum += a;
    }
    a = n - sum;

    cout << a << endl;
  }

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

#include <stdio.h>

int main() {
  int total;
  int sum = 0;
  int a;

  for (;;) {
    total = 0;
    sum = 0;
    scanf("%d", &total);
    if (total == 0) {
      break;
    }

    for (int i = 0; i < 9; i++) {
      scanf("%d", &a);
      sum += a;
    }

    printf("%d\\n", total - sum);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int total;
  int sum = 0;
  int a;

  for (;;) {
    scanf("%d", &total);
    if (total == 0) {
      break;
    }

    for (int i = 0; i < 9; i++) {
      scanf("%d", a);
      sum += a;
    }

    printf("%d\\n", total - sum);
  }
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
  }
}

Error: TLE

Fixed submission:

#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;
  }
}
Problem p00466 (C++) — buggy submission, verdict: 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 = total - (a + b + c + d + e + f + g + h + i);
    cout << j << '\\n';
    cin >> total;
  }
  return 0;
}

Error: TLE

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;
    j = total - (a + b + c + d + e + f + g + h + i);
    cout << j << '\\n';
    cin >> total;
  }
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int A;
  int B;
  cin >> A;
  while (1) {
    if (A == 0)
      break;
    for (int i = 0; i < 9; i++) {
      cin >> B;
      A -= B;
    }
    cout << A << endl;
    cin >> A;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int A;
  int B;
  while (1) {
    cin >> A;
    for (int i = 0; i < 9; i++) {
      cin >> B;
      A -= B;
    }
    cout << A << endl;
    cin >> A;
  }
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define Iset int i, j, l;
#define Fi for (i = 0; i < 9; i++)
using namespace std;

int main() {
  int a, b[11], c = 0;

  Iset;
  cin >> a;
start:
  Fi {
    cin >> b[i];
    c += b[i];
  }
  cout << a - c << endl;

  cin >> a;
  if (a == 0) {
    goto end;
  } else {
    c = 0;
    goto start;
  }
end:
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#define Iset int i, j, l;
#define Fi for (i = 0; i < 9; i++)
using namespace std;

int main() {
  int a, b[11], c = 0;
start:
  Iset;
  cin >> a;
  Fi {
    cin >> b[i];
    c += b[i];
  }
  cout << a - c << endl;

  cin >> a;
  if (a == 0) {
    goto end;
  } else {
    goto start;
  }
end:
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p00466 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int i, j, k;
  while (0)
    ;
  while (scanf("%d", &i), i) {
    for (k = 0; k < 9; k++)
      scanf("%d", &j), i -= j;
    printf("%d\\n", i);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int i, j, k;
  while (scanf("%d", &i), i) {
    for (k = 0; k < 10; k++)
      scanf("%d", &j), i -= j;
    printf("%d\\n", i);
  }
  return 0;
}
Problem p00466 (C++) — buggy submission, verdict: 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 < 9; b++) {
      cin >> c;
      d = d + c;
    }
    b = a - d;
    cout << b << endl;
  }
  return 0;
}

Error: TLE

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 < 10; b++) {
      cin >> c;
      d = d + c;
    }
    b = a - d;
    cout << b << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cwctype>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int map[1100] = {0};
    int dice[1001] = {0};
    for (int i = 1; i <= n; i++) {
      cin >> map[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> dice[i];
    }
    int count = 1;
    for (int i = 0; i < m; i++) {
      count += dice[i];
      count += map[count];
      if (count >= n) {

        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cwctype>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, !(n == 0 && m == 0)) {
    int map[1100] = {0};
    int dice[1001] = {0};
    for (int i = 1; i < n; i++) {
      cin >> map[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> dice[i];
    }
    int count = 1;
    for (int i = 0; i < m; i++) {
      count += dice[i];
      count += map[count];
      if (count >= n) {

        cout << i + 1 << endl;
        break;
      }
    }
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>

using namespace ::std;

int main(void) {

  int N, M;

  while (cin >> N >> M, !(N == 0 && M == 0)) {

    vector<int> map(N + 1);
    vector<int> dice(M + 1);

    for (int i = 1; i <= N; i++) {
      cin >> map[i];
    }

    for (int i = 1; i <= M; i++) {
      cin >> dice[i];
    }

    int now = 1;

    for (int i = 1; i <= M; i++) {
      now += dice[i];
      now += map[now];
      if (now >= N) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cwctype>
#include <fstream>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int map[2010] = {0};
int main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> map[i];
    }
    int count = 0;
    for (int i = 0; i < m; i++) {

      int c;
      cin >> c;
      count += c;
      count += map[count];
      if (count >= n - 1) {
        count = i + 1;
        break;
      }
    }

    cout << count << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: 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 (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;
}

Error: 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 (!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;
}
Problem p00467 (C++) — buggy submission, verdict: 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[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;
}

Error: 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[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;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, m, masu[1000];
  vector<int> result;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> masu[i];

    int dice, hoge = 0, i;
    for (i = 1; i <= m; i++) {
      cin >> dice;
      if (hoge + dice >= n - 1) {
        result.push_back(i);
        break;
      }
      hoge += dice + masu[hoge + dice];
      if (hoge >= n - 1) {
        result.push_back(i);
        break;
      }
      if (hoge < 0)
        hoge = 0;
    }
    for (int j = i + 1; j <= m; j++)
      cin >> dice;
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, m, masu[1000];
  vector<int> result;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> masu[i];

    int dice, hoge = 0;
    bool piyo = true;
    for (int i = 1; i <= m; i++) {
      cin >> dice;
      if (piyo && hoge + dice >= n - 1) {
        result.push_back(i);
        piyo = false;
      }
      hoge += dice + masu[hoge + dice];
    }
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int a[1000];
int main() {
  int n, m, b, pos = 0, ans = 0;
  scanf("%d%d", &n, &m);
  if (!(n | m))
    return 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b);
    pos += b;
    if (pos >= n - 1) {
      if (!ans)
        ans = i + 1;
      pos = 0;
    }
    pos += a[pos];
    if (pos >= n - 1 && !ans)
      ans = i + 1;
  }
  printf("%d\\n", ans);
  main();
}

Error: WA

Fixed submission:

#include <stdio.h>

int a[1000];
int b[1000];
int main() {
  int n, m, pos = 0;
  scanf("%d%d", &n, &m);
  if (!(n | m))
    return 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < m; i++)
    scanf("%d", &b[i]);
  for (int i = 0; i < m; i++) {
    pos += b[i];
    if (pos >= n - 1) {
      printf("%d\\n", i + 1);
      main();
    }
    pos += a[pos];
    if (pos >= n - 1) {
      printf("%d\\n", i + 1);
      main();
    }
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

int main(void) {
  int a;
  int nn, m;
  int b[1001];
  int n[1001];
  int p = 1;
  while (1) {
    for (a = 0; a <= 1000; a++) {
      n[a] = 0;
      b[a] = 0;
    }
    p = 1;
    cin >> nn >> m;
    if (nn == 0 && m == 0)
      break;
    for (a = 1; a <= nn; a++) {
      cin >> n[a];
    }
    for (a = 1; a <= m; a++) {
      cin >> b[a];
    }
    for (a = 1; a <= m; a++) {
      p += b[a];
      p += n[p];
      if (p >= nn) {
        printf("%d\\n", a);
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

int n[1001];
int p = 1;

void dice(int b) {
  p += b;
  p += n[p];
  return;
}

int main(void) {
  int a;
  int nn, m;
  int b;
  int ans = 10000;
  while (1) {
    for (a = 0; a <= 1000; a++) {
      n[a] = 0;
    }
    ans = 10000;
    cin >> nn >> m;
    if (nn == 0 && m == 0)
      break;
    for (a = 1; a <= nn; a++) {
      cin >> n[a];
    }
    for (a = 1; a <= m; a++) {
      cin >> b;
      dice(b);
      if (p >= nn) {
        if (ans > a)
          ans = a;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: 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[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;
}

Error: TLE

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[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;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define INF 1000000
using namespace std;
int main() {
  int sugo[2000];
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 2000; i++)
      sugo[i] = 0;
    for (int i = 1; i <= n; i++)
      cin >> sugo[i];
    int odr, p = 1, ans = 0;
    int f = 1;
    for (int i = 0; i < m; i++) {
      cin >> odr;
      if (f) {
        ans++;
        p += odr;
        p += sugo[p];
        if (p >= n - 1)
          f = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define INF 1000000
using namespace std;
int main() {
  int sugo[2000];
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < 2000; i++)
      sugo[i] = 0;
    for (int i = 1; i <= n; i++)
      cin >> sugo[i];
    int odr, p = 1, ans = 0;
    int f = 1;
    for (int i = 0; i < m; i++) {
      if (f)
        ans++;
      cin >> odr;
      p += odr;
      p += sugo[p];
      if (p >= n - 1 && f == 1)
        f = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1000], b[1000];
int main() {
  int n, m, t, p, ans;
  while (1) {
    scanf("%d%d", &n, &m);
    if (!n && !m)
      break;
    p = 0;
    rep(i, n) scanf("%d", &a[i]);
    rep(i, m) scanf("%d", &b[i]);
    for (int i = 0; i < m; i++) {
      p += b[i];
      if (p >= n - 1) {
        ans = i + 1;
        break;
      }
      p += a[p];
      if (p >= n - 1) {
        ans = i + 1;
        break;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1000];
int main() {
  int n, m, t, p, ans;
  while (1) {
    scanf("%d%d", &n, &m);
    if (!n && !m)
      break;
    p = 0;
    rep(i, n) scanf("%d", &a[i]);
    for (int i = 0; i < m; i++) {
      scanf("%d", &t);
      p += t;
      if (p >= n - 1) {
        ans = i + 1;
        break;
      }
      p += a[p];
      if (p >= n - 1) {
        ans = i + 1;
        break;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int N, M, masu[1000], dice[1000], now, i;
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    now = 1;
    for (i = 1; i <= N; i++)
      cin >> masu[i];
    for (i = 1; i <= M; i++)
      cin >> dice[i];
    for (i = 1; i <= M; i++) {
      now += dice[i];
      now += masu[now];
      if (now >= N)
        break;
    }
    cout << i << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, i;
  while (cin >> n >> m, (n != 0 && m != 0)) {
    int now = 1, ans = 0;
    vector<int> v(n + 5);
    for (i = 1; i <= n; i++) {
      cin >> v[i];
    }
    for (i = 1; i <= m; i++) {
      int num;
      cin >> num;
      now += num;
      if (now >= n) {
        if (ans == 0)
          ans = i;
      }
      now += v[now];
    }
    cout << ans << endl;
  }
  return 0;
}