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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int mod(int a, int b, int c, int x);

int main() {
  int n, a, b, c, x;
  while (cin >> n >> a >> b >> c >> x, n || a || b || c || x) {
    vector<int> y(n);

    for (int i = 0; i < n; i++) { // input
      cin >> y[i];
    }

    int i, j;
    for (i = 0, j = 0; i <= 10000; i++) {
      if (y[j] == x) {
        j++;
      }
      x = mod(a, b, c, x);
      if (j >= n) {
        break;
      }
    }

    if (i > 10000) {
      cout << -1 << endl;
    } else {
      cout << i << endl;
    }
  }

  return 0;
}

int mod(int a, int b, int c, int x) {
  int tmp = (a * x + b) % c;
  return tmp;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int mod(int a, int b, int c, int x);

int main() {
  int n, a, b, c, x;
  while (cin >> n >> a >> b >> c >> x, n || a || b || c || x) {
    vector<int> y(n);

    for (int i = 0; i < n; i++) { // input
      cin >> y[i];
    }

    int i, j;
    for (i = 0, j = 0; i < 10000, j < n; i++) {
      if (y[j] == x) {
        j++;
      }
      x = mod(a, b, c, x);
    }

    if (i > 10001) {
      cout << -1 << endl;
    } else {
      cout << i - 1 << endl;
    }
  }

  return 0;
}

int mod(int a, int b, int c, int x) {
  int tmp = (a * x + b) % c;
  return tmp;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int N, A, B, C, Y[110], i, n, X;

int ran(int x1, int i, int n) {
  int x2;
  if (Y[i] == x1 && i == N)
    return n; // 0回を出すためのもの
  if (x1 == Y[i]) {
    if (i == N)
      return n; // 最後止めるための条件
    else
      i++; // 整数と乱数の値が同じとき次の整数の検証に移る
  }
  x2 = (A * x1 + B) % C; // 乱数を計算
  n++;                   // リール数
  if (n > 10000)
    return -1; // それ以外は－１

  return ran(x2, i, n);
}

int main(void) {
  while (cin >> N >> A >> B >> C >> X) {
    if (N == 0 && A == 0 && B == 0 && C == 0 && X == 0)
      break;
    for (int i = 1; i <= N; i++)
      cin >> Y[i];
    cout << ran(X, 1, 0) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int N, A, B, C, Y[110], i, n, X;

int ran(int x1, int i, int n) {
  int x2;
  // if(Y[i] == x1)  return n;//0回を出すためのもの
  x2 = (A * x1 + B) % C; // 乱数を計算
  n++;                   // リール数
  if (x2 == Y[i]) {
    if (i == N)
      return n; // 最後止めるための条件
    else
      i++; // 整数と乱数の値が同じとき次の整数の検証に移る
  } else if (i > 10000)
    return -1; // それ以外は－１
  return ran(x2, i, n);
}

int main(void) {
  while (cin >> N >> A >> B >> C >> X) {
    if (N == 0 && A == 0 && B == 0 && C == 0 && X == 0)
      break;
    for (int i = 1; i <= N; i++)
      cin >> Y[i];
    if (Y[1] == X)
      cout << 0 << endl;
    else
      cout << ran(X, 1, 0) << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

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

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  int N, A, B, C, X;
  while (~scanf("%d %d %d %d %d", &N, &A, &B, &C, &X)) {
    // x' = (A × x + B) mod C
    if (N == 0)
      break;
    int count = 0;
    vector<int> Y;
    for (int i = 0; i < N; i++) {
      int y;
      scanf("%d", &y);
      Y.push_back(y);
    }

    if (Y[0] == X && Y.size() == 1) {
      goto last;
    }

    for (int i = 0; i < Y.size(); i++) {
      for (int j = 0; j <= 100000; j++) {
        if (i == 0 && Y[i] == X) {
          continue;
        }
        count++;
        X = (A * X + B) % C;
        if (Y[i] == X) {
          break;
        }
        if (count > 10000)
          goto last;
      }
    }

  last:;
    printf("%d\\n", count > 10000 ? -1 : count);
  }
}

Error: -11

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

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

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  int N, A, B, C, X;
  while (~scanf("%d %d %d %d %d", &N, &A, &B, &C, &X)) {
    // x' = (A × x + B) mod C

    int count = 0;
    vector<int> Y;
    for (int i = 0; i < N; i++) {
      int y;
      scanf("%d", &y);
      Y.push_back(y);
    }

    if (Y[0] == X) {
      goto last;
    }

    for (int i = 0; i < Y.size(); i++) {
      for (int j = 0; j < 100000; j++) {
        count++;
        X = (A * X + B) % C;
        if (Y[i] == X) {
          break;
        }
        if (count > 10000)
          goto last;
      }
    }

  last:;
    printf("%d\\n", count > 10000 ? -1 : count);
  }
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int list[100];
int main() {
  for (;;) {
    int n, a, b, c, x;
    cin >> n >> a >> b >> c >> x;
    if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
      break;
    memset(list, 0, sizeof(list));
    for (int i = 0; i < n; i++) {
      cin >> list[i];
    }
    int count = 0, index = 0;
    for (;;) {
      if (count > 10000) {
        cout << -1 << endl;
        break;
      }
      if (list[index] == x)
        index++;
      if (n == index) {
        cout << count << endl;
        break;
      }
      x = (a * x + b) % c;
      count++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
int v[10000];
using namespace std;
int main() {
  int n, a, b, c, x, t, l, p, y, s;
  for (;;) {
    cin >> n >> a >> b >> c >> x;
    if (n == 0)
      break;
    memset(v, -1, sizeof(v));
    v[x] = 0;
    t = (a * x + b) % c;
    l = 1;
    while (t != x) {
      v[t] = l++;
      t = (a * t + b) % c;
    }
    cin >> p;
    s = v[p];
    while (--n) {
      cin >> y;
      if (v[y] == -1) {
        s = -1;
      } else if (s >= 0) {
        if (v[p] >= v[y]) {
          s += l - (v[p] - v[y]);
        } else {
          s += v[y] - v[p];
        }
      }
      p = y;
    }
    if (s > 10000)
      s = -1;
    cout << s << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;

int N, A, B, C, X, Y[200];

int main(void) {
  while (cin >> N >> A >> B >> C >> X, N) {
    REP(i, 0, N) cin >> Y[i];

    int ans = 0, k = 0;
    while (ans <= 10000) {
      if (X == Y[k]) {
        k++;
        if (k == N)
          break;
      }
      X = (((A % C) * X) % C + B) % C;
      ans++;
    }
    cout << (ans <= 10000 ? ans : -1) << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;

int N, A, B, C, X, Y[200];

int main(void) {
  while (cin >> N >> A >> B >> C >> X) {
    REP(i, 0, N) cin >> Y[i];

    int ans = 0, k = 0;
    while (ans <= 10000) {
      if (X == Y[k]) {
        k++;
        if (k == N)
          break;
      }
      X = (((A % C) * X) % C + B) % C;
      ans++;
    }
    cout << (ans <= 10000 ? ans : -1) << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, a, b, c, x, y[100];
  while (1) {
    int count = 0;
    cin >> n >> a >> b >> c >> x;
    if ((n + a + b + c + x) == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> y[i];
    int j = 0;
    while (1) {
      if (y[j] == x)
        j++;
      if (n == j)
        break;
      else {
        x = (a * x + b) % c;
        count++;
      }
      if (count > 10000)
        break;
    }
    if (count <= 10000)
      cout << count << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, a, b, c, x, y[100];
  while (1) {
    int count = 0;
    cin >> n >> a >> b >> c >> x;
    if ((n + a + b + c + x) == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> y[i];
    int j = 0;
    while (1) {
      if (y[j] == x)
        j++;
      else if (n == j)
        break;
      else {
        x = (a * x + b) % c;
        count++;
      }
    }

    if (count <= 10000)
      cout << count << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int x[200000], n, a, b, c, d, p, rell, y[200000];
int main() {
  while (true) {
    cin >> n >> a >> b >> c >> p;
    if (!n) {
      break;
    }
    x[0] = p;
    rell = 0;
    for (int i = 1; i < 200000; i++) {
      x[i] = (x[i - 1] * a + b) % c;
    }
    for (int i = 0; i < n; i++) {
      cin >> y[i];
    }
    for (int i = 0; i < 10001; i++) {
      if (y[rell] == x[i]) {
        rell++;
      }
      if (rell == n) {
        d = i;
        goto E;
      }
    }
    d = -1;
  E:;
    cout << d << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int y, a, b, c, n, x, i, j, s;
int main() {
  while (true) {
    cin >> n >> a >> b >> c >> x;
    if (!n) {
      break;
    }
    s = -1;
    for (i = 0; i < n; i++) {
      cin >> y;
      while (y != x) {
        x = (a * x + b) % c;
        s++;
        if (s > 10000) {
          s = -1;
          break;
        }
      }
      s++;
      x = (a * x + b) % c;
      if (s > 10000) {
        s = -1;
        break;
      }
    }
    cout << s << endl;
  }
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#pragma warning(disable : 4996)
int N, A, B, C, X, Y[100], P;
int main() {
  while (true) {
    scanf("%d%d%d%d%d", &N, &A, &B, &C, &X);
    if (N == 0 && A == 0 && B == 0 && C == 0 && X == 0)
      break;
    for (int i = 0; i < N; i++)
      scanf("%d", &Y[i]);
    P = 0;
    bool flag = false;
    for (int i = 0; i <= 10000; i++) {
      if (X == Y[P])
        P++;
      if (N == P) {
        printf("%d\\n", i);
        flag = true;
        break;
      }
      X = (A * X + B) % C;
    }
    if (!flag) {
      printf("-1\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#pragma warning(disable : 4996)
int N, A, B, C, X, Y, Q[10001];
int main() {
  while (true) {
    scanf("%d%d%d%d%d", &N, &A, &B, &C, &X);
    for (int i = 0; i < N; i++)
      scanf("%d", &Y), Q[Y]++;
    bool flag = false;
    for (int i = 0; i <= 10000; i++) {
      if (Q[X] > 0)
        Q[X]--, N--;
      if (N == 0) {
        printf("%d\\n", i);
        flag = true;
        break;
      }
      X = (A * X + B) % C;
    }
    if (!flag) {
      printf("-1\\n");
    }
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, a, b, c, x, f[10001], now, key[100], i;
  while (1) {
    cin >> n >> a >> b >> c >> x;
    if (n == 0)
      break;
    f[0] = x;
    for (i = 1; i <= 10000; i++)
      f[i] = (f[i - 1] * a + b) % c;
    for (i = 0; i < n; i++)
      cin >> key[i];
    now = 0;
    for (i = 0; i <= 10000; i++) {
      if (key[now] == f[i])
        now++;
      if (now >= n)
        break;
    }
    if (i == 10001)
      cout << "-1" << endl;
    else
      cout << i << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <stdio.h>
int main() {
  int n, a, b, c, x, cou, i, t;
  while (1) {
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &x);
    if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
      break;
    cou = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &t);
      if (t == x && cou == 0)
        continue;
      while (1) {
        x = (a * x + b) % c;
        cou++;
        if (x == t)
          break;
        if (cou > 10000) {
          printf("-1\\n");
          for (i = i; i < n; i++)
            scanf("%d", &t);
          break;
        }
      }
      if (cou > 10000)
        break;
    }
    if (cou <= 10000)
      printf("%d\\n", cou);
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, a, b, c, x;
  while (cin >> n >> a >> b >> c >> x, n) {
    int cnt = 0, y[100];
    for (int i = 0; i < n; i++) {
      cin >> y[i];
    }
    int idx = 0;
    while (1) {
      if (cnt > 10000)
        break;
      if (x == y[idx])
        idx++;
      if (idx >= n)
        break;
      x = (a * x + b) % c;
      cnt++;
    }
    if (cnt > 10000) {
      cout << -1 << endl;
    } else {
      cout << cnt << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, a, b, c, x;
  while (cin >> n >> a >> b >> c >> x, n) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      int y;
      cin >> y;
      if (y == x)
        break;
      while (cnt <= 10000) {
        x = (a * x + b) % c;
        cnt++;
        if (x == y)
          break;
      }
    }
    if (cnt == 10001)
      cout << -1 << endl;
    else
      cout << cnt << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, a, b, c, x, y;
  while (1) {
    cin >> n >> a >> b >> c >> x;
    if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) {
      break;
    }
    int f = 0;
    for (int i = 0; i < n; i++) {
      cin >> y;
      if (f != -1) {
        while (1) {
          if (y == x) {
            if (n != i + 1) {
              x = (a * x + b) % c;
              f++;
            }
            break;
          }
          x = (a * x + b) % c;
          f++;
          if (f > 10000) {
            f = -1;
            break;
          }
        }
      }
    }
    cout << f << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, a, b, c, x, y;
  while (1) {
    cin >> n >> a >> b >> c >> x;
    if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
      break;
    int f = 0;
    for (int i = 0; i < n; i++) {
      cin >> y;
      while (10000 >= f) {
        if (y == x) {
          if (n != i + 1) {
            x = (a * x + b) % c;
            f++;
          }
          break;
        }
        x = (a * x + b) % c;
        f++;
      }
      if (f > 10000) {
        f = -1;
        break;
      }
    }
    cout << f << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, a, b, c, x;
  while (1) {
    cin >> n >> a >> b >> c >> x;
    if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
      break;
    int y[200], next_x = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> y[i];
    }
    int now_y;
    for (int i = 0; i < n; i++) {
      now_y = y[i];
      while (1) {
        next_x = (a * x + b) % c;
        if (y[i] == x) {
          if (i != n - 1)
            cnt++;
          x = next_x;
          break;
        } else {
          cnt++;
          if (cnt > 10000) {
            cnt = -1;
            i = 200;
            break;
          } else
            x = next_x;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, a, b, c, x;
  while (1) {
    cin >> n >> a >> b >> c >> x;
    if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
      break;
    int y = 0, next_x = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> y;
      while (1) {
        next_x = (a * x + b) % c;
        if (y == x) {
          if (i != n - 1)
            cnt++;
          x = next_x;
          break;
        } else {
          cnt++;
          if (cnt > 10000) {
            cnt = -1;
            i = 200;
            break;
          } else
            x = next_x;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define limit 10000

using namespace std;

int main() {
  while (true) {

    int N, A, B, C, X;

    int pic[100];

    int count = 0;
    int ans = -1;

    cin >> N >> A >> B >> C >> X;

    if (N + A + B + C + X == 0)
      break;

    int x;
    x = X;

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

    for (int i = 0; i < limit + 1; i++) {

      if (x == pic[count]) {
        count++;
        ans = i;
      }

      if (x + B == 0 && pic[count] != 0)
        break;

      if (count == N)
        break;

      x = (A * x + B) % C;
    }

    if (count != N)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#define limit 10000

using namespace std;

int main() {
  while (true) {

    int N, A, B, C, X;

    int pic[100];

    int count = 0;
    int ans = -1;

    cin >> N >> A >> B >> C >> X;

    if (N + A + B + C + X == 0)
      break;

    int x;
    int nx;
    x = X;

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

    for (int i = 0; i < limit + 1; i++) {

      if (x == pic[count]) {
        count++;
        ans = i;
      }

      if (x + B == 0 && pic[count] != 0)
        break;

      if (count == N)
        break;

      nx = (A * x + B) % C;
      x = nx;
    }

    if (count != N)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  while (true)
    ;
}
Problem p01267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int N, A, B, C, X;
  while (cin >> N >> A >> B >> C >> X, N || A || B || C || X) {
    int Y[100];
    for (int i = 0; i < N; ++i) {
      cin >> Y[i];
    }
    int need[10001] = {0};
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
      if (!need[Y[i]])
        ++cnt;
      ++need[Y[i]];
    }

    int ans = -1;
    int pos = 0;
    for (int t = 0; t <= 10000; ++t) {
      if (Y[pos] == X) {
        if (++pos == N) {
          ans = t;
          break;
        }
      }
      X = (A * X + B) % C;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N, A, B, C, X;
  while (cin >> N >> A >> B >> C >> X, N || A || B || C || X) {
    int Y[100];
    for (int i = 0; i < N; ++i) {
      cin >> Y[i];
    }
    int need[10001] = {0};
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
      if (!need[Y[i]])
        ++cnt;
      ++need[Y[i]];
    }

    int ans = -1;
    int pos = 0;
    for (int t = 0; t < 10000 * 1000; ++t) {
      if (Y[pos] == X) {
        if (++pos == N) {
          ans = t;
          break;
        }
      }
      X = (A * X + B) % C;
    }
    cout << ans << endl;
  }
}
Problem p01267 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
  int n, a, b, c, x;
  int y[101];
  while (cin >> n >> a >> b >> c >> x && n) {
    for (int i = 0; i < n; i++) {
      cin >> y[i];
    }
    int cont = 0, icont = 0;
    if (x == y[0])
      icont++;
    while (cont <= 10000 && icont < n) {
      x = (a * x + b) % c;
      if (x == y[icont]) {
        icont++;
      }
      cont++;
    }
    if (cont > 10000) {
      cout << -1 << endl;
    } else
      cout << cont << endl;
  }
}

Error: 0
sh: 1: pause: not found


Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
  int n, a, b, c, x;
  int y[101];
  while (cin >> n >> a >> b >> c >> x && n) {
    for (int i = 0; i < n; i++) {
      cin >> y[i];
    }
    int cont = 0, icont = 0;
    if (x == y[0])
      icont++;
    while (cont <= 10000 && icont < n) {
      x = (a * x + b) % c;
      if (x == y[icont]) {
        icont++;
      }
      cont++;
    }
    if (cont > 10000) {
      cout << -1 << endl;
    } else
      cout << cont << endl;
  }
  system("pause");
}
Problem p01267 (C++) — buggy submission, verdict: Runtime Error

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

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define print(a) cout << a << "\\n"
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\\n'

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

  int N, A, B, C, X;
  int r[10001];
  int y[10001];

  while (true) {
    cin >> N >> A >> B >> C >> X;
    if (N + A + B + C + X == 0) {
      break;
    }
    r[0] = X;
    REP(i, 10000) { r[i + 1] = (A * r[i] + B) % C; }

    REP(i, N) { cin >> y[i]; }

    int n = 0;
    REP(i, N) {
      if (n == -1) {
        break;
      }
      while (true) {
        // if(y[i + 1] == y[i]) {
        //   n++;
        // }
        if (y[i] == r[n]) {
          n++;
          break;
        }

        if (n > 10000) {
          n = -1;
          break;
        }
        n++;
      }
    }
    if (n == -1) {
      cout << n << endl;
    } else {
      cout << --n << endl;
    }
  }
  return 0;
}


Error: -8

Fixed submission:

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

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define print(a) cout << a << "\\n"
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\\n'

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

  int N, A, B, C, X;
  int r[100001];
  int y[100001];

  while (true) {
    cin >> N >> A >> B >> C >> X;
    r[0] = X;
    REP(i, 100000) { r[i + 1] = (A * r[i] + B) % C; }

    REP(i, N) { cin >> y[i]; }

    int n = 0;
    REP(i, N) {
      if (n == -1) {
        break;
      }
      while (true) {
        if (y[i] == r[n]) {
          break;
        }
        n++;
        if (n > 100000) {
          n = -1;
          break;
        }
      }
    }

    cout << n << endl;
    // print(n);
  }
}