alexjercan/bugnet huggingface dataset:
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int H[101];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (cin >> N) {
    if (N == 0)
      break;
    N++;
    rep(i, N) cin >> H[i];
    int w = -1;
    rep(i, N) {
      vector<int> xs;
      rep(j, i) xs.pb(H[j]);
      for (int j = i + 1; j < N; j++)
        xs.pb(H[j]);
      int diff = xs[1] - xs[0];
      bool f = true;
      rep(i, (int)xs.size() - 1) {
        if (diff != xs[i + 1] - xs[i])
          f = false;
      }
      if (f) {
        w = H[i];
        break;
      }
    }
    cout << w << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int H[100];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (cin >> N) {
    if (N == 0)
      break;
    N++;
    rep(i, N) cin >> H[i];
    int w = -1;
    rep(i, N) {
      vector<int> xs;
      rep(j, i) xs.pb(H[j]);
      for (int j = i + 1; j < N; j++)
        xs.pb(H[j]);
      int diff = xs[1] - xs[0];
      bool f = true;
      rep(i, (int)xs.size() - 1) {
        if (diff != xs[i + 1] - xs[i])
          f = false;
      }
      if (f) {
        w = H[i];
        break;
      }
    }
    cout << w << "\\n";
  }
  return 0;
}
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int x, n, h[101], r[100], s[99], i, j, flg;
  while (1) {
    flg = 0;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n + 1; i++) {
      scanf("%d", &h[i]);
    }
    for (i = 0; i < n + 1; i++) {
      for (j = 0; j < n; j++) {
        if (j >= i) {
          r[j] = h[j + 1];
        } else {
          r[j] = h[j];
        }
      }
      for (j = 0; j < n - 1; j++) {
        s[j] = r[j + 1] - r[j];
      }
      for (j = 0; j < n - 2; j++) {
        if (s[j] != s[j + 1]) {
          flg = 0;
          break;
        }
        if (s[j] == s[j + 1]) {
          flg = 1;
        }
      }
      if (flg == 1) {
        x = h[i];
        i = 1000;
      }
    }
    printf("%d\\n", x);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int x, n, h[101], r[10], s[99], i, j, flg;
  while (1) {
    flg = 0;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n + 1; i++) {
      scanf("%d", &h[i]);
    }
    for (i = 0; i < n + 1; i++) {
      for (j = 0; j < n; j++) {
        if (j >= i) {
          r[j] = h[j + 1];
        } else {
          r[j] = h[j];
        }
      }
      for (j = 0; j < n - 1; j++) {
        s[j] = r[j + 1] - r[j];
      }
      for (j = 0; j < n - 2; j++) {
        if (s[j] != s[j + 1]) {
          flg = 0;
          break;
        }
        if (s[j] == s[j + 1]) {
          flg = 1;
        }
      }
      if (flg == 1) {
        x = h[i];
        i = 1000;
      }
    }
    printf("%d\\n", x);
  }
  return 0;
}
Problem p00253 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int n, a[1000], s;
vector<int> p;
int main() {
  while (true) {
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n + 1; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n + 1; i++) {
      p.clear();
      for (int j = 0; j < n + 1; j++) {
        if (i != j) {
          p.push_back(a[j]);
        }
      }
      for (int j = 0; j < p.size() - 1; j++) {
        if (j == 0) {
          s = p[j + 1] - p[j];
        } else if (p[j + 1] - p[j] != s) {
          goto E;
        }
      }
      cout << a[i] << endl;
      goto otawa;
    E:;
    }
  otawa:;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int n, a[1000], s;
vector<int> p;
int main() {
  while (true) {
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      p.clear();
      for (int j = 0; j < n; j++) {
        if (i != j) {
          p.push_back(a[j]);
        }
      }
      for (int j = 0; j < p.size() - 1; j++) {
        if (i == 0) {
          s = a[j + 1] - a[j];
        } else if (a[j + 1] - a[j] != s) {
          goto E;
        }
      }
      cout << a[i] << endl;
      goto otawa;
    E:;
    }
  otawa:;
  }
}
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
const int INF = 1e9;
bool check(vector<int> t) {
  int dif = t[1] - t[0];
  rep2(i, 2, t.size()) {
    if (t[i] - t[i - 1] != dif)
      return true;
  }
  return false;
}
int main() {
  int n;
  while (cin >> n, n) {
    int x[110] = {};
    rep(i, n + 1) { cin >> x[i]; }
    rep(i, n + 1) {
      vector<int> v;
      rep(j, n + 1) {
        if (i == j)
          continue;
        v.push_back(x[j]);
      }
      if (!check(v)) {
        cout << x[i] << endl;
        break;
      }
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
const int INF = 1000000000;
int main() {
  int n;
  while (cin >> n, n) {
    int x[110] = {}, a[3];
    fill(a, a + 3, INF);
    vector<int> v[3];
    rep(i, n + 1) { cin >> x[i]; }
    rep(i, n) {
      rep(j, 3) {
        if (a[j] == INF) {
          a[j] = x[i + 1] - x[i];
          v[j].push_back(i);
          break;
        } else if (a[j] == x[i + 1] - x[i]) {
          v[j].push_back(i);
          break;
        }
      }
    }
    int cnt = 0;
    rep(i, 3) {
      a[i] = v[i].size();
      if (a[i] == 1)
        cnt++;
    }
    if (cnt == 1) {
      rep(i, 3) {
        if (a[i] == 1) {
          int ret = v[i][0] == 0 ? v[i][0] : v[i][0] + 1;
          cout << x[ret] << endl;
        }
      }
    } else {
      int ret = 0, diff = (x[n] - x[0]) / n;
      rep(i, 3) {
        if (a[i] != diff)
          ret = ret > v[i][0] ? ret : v[i][0];
      }
      cout << x[ret] << endl;
    }
  }
}
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
vector<int> h(102);
int f(int, int);
int main(void) {
  int ans;
  int n, count = 0;
  vector<int> a(501);
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n + 1; i++)
      cin >> h[i];

    for (int i = 0; i < n - 2; i++) {
      if ((h[i + 3] - h[i + 2]) - (h[i + 1] - h[i]) != 0) {
        ans = h[f(i, n)];
      }
    }
    a[count] = ans;
    count += 1;
    h.clear();
  }
  for (int i = 0; i < count; i++)
    cout << a[i] << endl;
  return 0;
}
int f(int i, int n) {
  int c = 0, k;
  int a;
  vector<int> dh(102);
  for (int j = i; j < i + 4; j++) {
    for (k = 0; k < n + 1; k++) {
      if (k == j)
        continue;
      dh[c] = h[k];
      c++;
    }
    a = dh[1] - dh[0];
    for (k = 0; k < c - 1 && a == dh[k + 1] - dh[k]; k++)
      ;
    if (k == c - 1)
      return j;
    dh.clear();
    c = 0;
  }
  return -1;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n, ans, count = 0;
  vector<int> a(500);
  vector<int> h;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    h.resize(n);
    for (int i = 0; i < n + 1; i++)
      cin >> h[i];

    for (int i = 0; i < n - 2; i++) {
      if ((h[i + 3] - h[i + 2]) - (h[i + 1] - h[i]) != 0) {
        if (h[i + 3] - h[i + 2] == h[i + 2] - h[i + 1])
          ans = h[i];
        else if (h[i + 3] - h[i + 2] == h[i + 2] - h[i])
          ans = h[i + 1];
        else if (h[i + 3] - h[i + 1] == h[i + 1] - h[i])
          ans = h[i + 2];
        else if (h[i + 2] - h[i + 1] == h[i + 1] - h[i])
          ans = h[i + 3];
        break;
      }
    }
    a[count] = ans;
    count += 1;
    h.clear();
  }
  for (int i = 0; i < count; i++)
    cout << a[i] << endl;
  return 0;
}
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  for (int n; cin >> n && n;) {
    vector<int> l(n + 1);
    for (int i = 0; i <= n; i++)
      cin >> l[i];
    for (int s = 0; s <= n; s++) {
      int diff = INT_MAX;
      for (int i = s ? 1 : 2; i <= n; i++) {
        if (i == s)
          continue;
        int be = i == s + 1 ? 2 : 1;
        if (diff == INT_MAX) {
          diff = l[i] - l[i - be];
        } else if (diff != l[i] - l[i - be]) {
          goto BREAK;
        }
      }
      cout << l[s] << endl;
      break;
    BREAK:;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  for (int n; cin >> n && n;) {
    vector<int> l(n);
    for (int i = 0; i <= n; i++)
      cin >> l[i];
    for (int s = 0; s <= n; s++) {
      int diff = INT_MAX;
      for (int i = s ? 1 : 2; i <= n; i++) {
        if (i == s)
          continue;
        int be = i == s + 1 ? 2 : 1;
        if (diff == INT_MAX) {
          diff = l[i] - l[i - be];
        } else if (diff != l[i] - l[i - be]) {
          goto BREAK;
        }
      }
      cout << l[s] << endl;
      break;
    BREAK:;
    }
  }
}
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
bool sol(vector<ll> v) {
  ll d = v[1] - v[0];
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != v[0] + d * i)
      return false;
  }
  return true;
}
int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    ll d[200];
    vector<ll> vv;
    vector<ll> v[200];
    for (int i = 0; i <= n; i++) {
      cin >> d[i];
      vv.push_back(d[i]);
      for (int j = 0; j <= n; j++) {
        if (i == j)
          continue;
        v[j].push_back(d[i]);
      }
    }
    assert(!sol(vv));
    set<int> s;
    int u = 0;
    for (int i = 0; i <= n; i++) {
      if (sol(v[i])) {
        u++;
        //        cout << d[i] << endl;
        s.insert(d[i]);
        // break;
      }
    }
    assert(s.size() == 1);
    cout << *s.begin() << endl;
    // assert(u <= 1);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
bool sol(vector<ll> v) {
  ll d = v[1] - v[0];
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != v[0] + d * i)
      return false;
  }
  return true;
}
int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    ll d[200];
    vector<ll> vv;
    vector<ll> v[200];
    for (int i = 0; i <= n; i++) {
      cin >> d[i];
      vv.push_back(d[i]);
      for (int j = 0; j <= n; j++) {
        if (i == j)
          continue;
        v[j].push_back(d[i]);
      }
    }
    // assert(!sol(vv));
    int u = 0;
    for (int i = 0; i <= n; i++) {
      if (sol(v[i])) {
        u++;
        cout << d[i] << endl;
        // break;
      }
    }
    assert(u <= 1);
  }
  return 0;
}
Problem p00253 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int n, h[101];
int ans[500], cor = 0;
int main() {
  int i, j;
  while (cin >> n) {
    if (n == 0)
      break;
    n++;
    for (i = 0; i < n; i++)
      cin >> h[i];
    // 雑草を抜いたら等差数列になるかも…
    int before, now, d;
    bool flag;
    for (i = 0; i < n; i++) {
      flag = false;
      for (j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (flag == false) {
          flag = true;
          before = h[j];
          if (i != j + 1)
            d = h[j + 1] - h[j];
          else
            d = h[j + 2] - h[j];
        } else {
          now = h[j];
          if (now - before != d)
            break;
          before = now;
        }
      }
      if (j == n) {
        ans[cor] = h[i];
        break;
      }
    }
    cor++;
  }
  for (i = 0; i < cor; i++)
    cout << ans[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n, h[100];
int ans[500], cor = 0;
int main() {
  int i, j;
  while (cin >> n) {
    if (n == 0)
      break;
    n++;
    for (i = 0; i < n; i++)
      cin >> h[i];
    // 雑草を抜いたら等差数列になるかも…
    int before, now, d;
    bool flag;
    for (i = 0; i < n; i++) {
      flag = false;
      for (j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (flag == false) {
          flag = true;
          before = h[j];
          if (i != j + 1)
            d = h[j + 1] - h[j];
          else
            d = h[j + 2] - h[j];
        } else {
          now = h[j];
          if (now - before != d)
            break;
          before = now;
        }
      }
      if (j == n) {
        ans[cor] = h[i];
        break;
      }
    }
    cor++;
  }
  for (i = 0; i < cor; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p00253 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  // 入力変数
  int n = 0;
  // 入力配列
  int h_input[101] = {0};
  // 一時入力変数
  int h_hozon[101] = {0};

  while (true) {
    cin >> n;

    if (n == 0) {
      return 0;
    }

    // 入力する
    for (int i = 0; i <= n; i++) {
      cin >> h_input[i];
    }

    for (int i = 0; i <= n; i++) {
      int count = 0;
      for (int j = 0; j <= n; j++) {
        if (i != j) {
          h_hozon[count++] = h_input[j];
        }
      }

      // forを回して調べる
      int sa = h_hozon[1] - h_hozon[0];

      int k = 0;
      for (k = 0; k < n - 1; k++) {
        if (h_hozon[k] + sa != h_hozon[k + 1]) {
          break;
        }
      }
      if (k == n - 1) {
        cout << h_input[i] << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  // 入力変数
  int n = 0;
  // 入力配列
  int h_input[100] = {0};
  // 一時入力変数
  int h_hozon[100] = {0};

  while (true) {
    cin >> n;

    // 入力する
    for (int i = 0; i <= n; i++) {
      cin >> h_input[i];
    }

    for (int i = 0; i <= n; i++) {
      int count = 0;
      for (int j = 0; j <= n; j++) {
        if (i != j) {
          h_hozon[count++] = h_input[j];
        }
      }

      // forを回して調べる
      int sa = h_hozon[1] - h_hozon[0];

      int k = 0;
      for (k = 0; k < n - 1; k++) {
        if (h_hozon[k] + sa != h_hozon[k + 1]) {
          break;
        }
      }
      if (k == n - 1) {
        cout << h_input[i] << endl;
        break;
      }
    }
  }

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

#include <cstdio>

int n;
int h[101];
int arr[100];

int main() {
  while (1) {
    scanf("%d", &n);

    if (n == 0)
      break;

    for (int i = 0; i < n + 1; ++i) {
      scanf("%d", &h[i]);
    }

    int ans = -1;
    for (int i = 0; i < n + 1; ++i) {
      for (int j = 0; j < n + 1; ++j) {
        if (i == j)
          continue;
        arr[j - (j > i)] = h[j];
      }
      int d = arr[1] - arr[0];
      bool flag = true;
      for (int j = 1; j < n; ++j) {
        flag &= (arr[j] - arr[j - 1]) == d;
      }
      if (flag) {
        // 3
        // 1 2 3 5
        // printf("%d\\n", h[i]);
        ans = h[i];
      }
    }

    printf("%d\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int n;
int h[101];
int arr[100];

int main() {
  while (1) {
    scanf("%d", &n);

    if (n == 0)
      break;

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

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (i == j)
          continue;
        arr[j - (j > i)] = h[j];
      }
      int d = arr[1] - arr[0];
      bool flag = true;
      for (int j = 1; j < n - 1; ++j) {
        flag &= (arr[j] - arr[j - 1]) == d;
      }
      if (flag) {
        printf("%d\\n", h[i]);
      }
    }
  }

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

#include <iostream>
using namespace std;
int main() {
  int n, a, c, j;
  int b[105];
  int s[505];
  int i = 0;
  while (cin >> n && n) {
    n++;
    for (j = 0; j < n; j++) {
      cin >> b[j];
    }
    c = b[1] - b[0];
    for (j = 1; j < n - 1; j++) {
      if (c != b[j + 1] - b[j]) {
        if (j == 1) {
          c = b[4] - b[3];
          a = b[1] - b[0];
          if (c != a) {
            if (c == b[2] - b[0]) {
              j = 0;
            } else {
              j = -1;
            }
          }
        }
        if (j == 2) {
          if (b[2] - b[0] == b[4] - b[3]) {
            j = 0;
          }
        }
        j++;
        break;
      }
    }
    s[i] = b[j];
    i++;
  }
  for (j = 0; j < i; j++) {
    cout << s[j] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, a, c, j;
  int b[105];
  int s[105];
  int i = 0;
  while (cin >> n && n) {
    n++;
    for (j = 0; j < n; j++) {
      cin >> b[j];
    }
    c = b[1] - b[0];
    for (j = 1; j < n - 1; j++) {
      if (c != b[j + 1] - b[j]) {
        if (j == 1) {
          c = b[4] - b[3];
          a = b[1] - b[0];
          if (c != a) {
            if (c == b[2] - b[0]) {
              j = 0;
            } else {
              j = -1;
            }
          }
        }
        if (j == 2) {
          if (b[2] - b[0] == b[4] - b[3]) {
            j = 0;
          }
        }
        j++;
        break;
      }
    }
    s[i] = b[j];
    i++;
  }
  for (j = 0; j < i; j++) {
    cout << s[j] << endl;
  }
  return 0;
}
Problem p00253 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> v(n + 1);
    for (auto &i : v)
      cin >> i;

    int ans = 0;
    for (int i = 0; i < n + 1; i++) {
      auto d = v;
      d.erase(d.begin() + i);
      vector<int> sub(n - 1);
      for (int j = 0; j < n - 1; j++) {
        sub[j] = d[j + 1] - d[j];
      }
      bool flag = true;
      for (int j = 0; j < n - 2; j++)
        if (sub[j + 1] - sub[j])
          flag = false;
      if (flag)
        ans = v[i];
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  while (1) {
    int num;
    cin >> num;

    if (num == 0)
      break;

    double vegetable[101] = {0};

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

    int ans = 0;
    double kiso;

    if (((vegetable[3] - vegetable[1]) / 2 + vegetable[1]) == vegetable[2]) {
      kiso = (vegetable[3] - vegetable[1]) / 2;
      for (int i = 1; i < num + 1; i++) {
        if ((vegetable[i] + kiso) != vegetable[i + 1]) {
          ans = vegetable[i + 1];

          if (i + 1 == 4) {
            double tmpp = ((vegetable[4] - vegetable[1]) / 2 + vegetable[1]);
            kiso = (vegetable[4] - vegetable[1]) / 2;
            if (tmpp == vegetable[3]) {
              ans = vegetable[2];
              for (int k = 3; k < num + 1; k++) {
                tmpp += kiso;
                if (tmpp != vegetable[k + 1]) {
                  ans = vegetable[k + 1];
                }
              }
            }
          }
          break;
        }
      }
    } else {
      if (((vegetable[4] - vegetable[2]) / 2 + vegetable[2]) == vegetable[3]) {
        ans = vegetable[1];
      } else {
        if (((vegetable[4] - vegetable[1]) / 2 + vegetable[1]) ==
            vegetable[2]) {
          ans = vegetable[3];
        } else {
          ans = vegetable[2];
        }
      }
    }
    cout << ans << endl;
  }

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

#include <iostream>

const int NOT = -10000000000;
int num;
int *data;

int fun() {
  int out, d = NOT;
  int j2;
  bool flag = false;
  for (int i = 0; i < num; i++) {
    out = data[i];
    for (int j = 0; j < num; j++) {
      if (i == j) {
        j2 = j - 1;
        continue;
      }
      if (d == NOT) {
        if (j + 1 != i) {
          d = data[j + 1] - data[j];
        } else {
          d = data[j + 2] - data[j];
        }
      } else {
        if (d != data[j] - data[j2]) {
          d = NOT;
          break;
        }
      }
      j2 = j;
    }
    if (d != NOT) {
      break;
    }
  }
  return out;
}

int main() {
  std::cin >> num;
  while (num) {
    num++;
    data = new int[num];
    for (int i = 0; i < num; i++) {
      std::cin >> data[i];
    }
    std::cout << fun() << std::endl;
    delete[] data;
    std::cin >> num;
  }
}

Error: 0

Fixed submission:

#include <deque>
#include <iostream>

int main() {
  int num;
  int in_data;
  int front, back;
  int dbace;
  std::cin >> num;
  while (num) {
    std::deque<int> data;
    num++;
    for (int i = 0; i < num; i++) {
      std::cin >> in_data;
      data.push_back(in_data);
    }
    front = data.front();
    data.pop_front();
    back = data.back();
    data.pop_back();
    if (data.front() - front == back - data.back()) {
      dbace = data.front() - front;
      do {
        front = data.front();
        data.pop_front();
        back = data.back();
        data.pop_back();
      } while (data.front() - front == back - data.back());
      if (dbace != data.front() - front) {
        std::cout << data.front() << std::endl;
      } else {
        std::cout << data.back() << std::endl;
      }
    } else {
      int front2, back2;
      front2 = data.front();
      data.pop_front();
      back2 = data.back();
      data.pop_back();
      if (data.front() - front2 == back2 - data.back()) {
        if (front2 - front != data.front() - front2) {
          std::cout << front << std::endl;
        } else {
          std::cout << back << std::endl;
        }
      } else {
        if (data.front() - front == back - back2) {
          std::cout << front2 << std::endl;
        } else {
          std::cout << back2 << std::endl;
        }
      }
    }
    std::cin >> num;
  }
}