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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i << 1
#define rs ls | 1
#define mid ((ll + rr) >> 1)
#define pii pair<int, int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17 + 1LL;
const double Pi = acos(-1.0);
const int N = 5e3 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9 + 10;

LL sum;
int n, a[N], d[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), sum += a[i];
  if (sum % (1LL * n * (n + 1) / 2)) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    d[i] = a[i] - a[i - 1];
  LL k = sum / (1LL * n * (n + 1) / 2);
  for (int i = 1; i <= n; ++i) {
    if (((d[i] - k) % n + n) % n && d[i] - k < 0) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i << 1
#define rs ls | 1
#define mid ((ll + rr) >> 1)
#define pii pair<int, int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17 + 1LL;
const double Pi = acos(-1.0);
const int N = 5e5 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9 + 10;

LL sum;
int n, a[N], d[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), sum += a[i];
  if (sum % (1LL * n * (n + 1) / 2)) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    d[i] = a[i] - a[i - 1];
  LL k = sum / (1LL * n * (n + 1) / 2);
  for (int i = 1; i <= n; ++i) {
    if (((d[i] - k) % n + n) % n && d[i] - k < 0) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
Problem p03808 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 200006
using namespace std;
long long n, x, ans, a[N], b[N], p, sum, f[N], fsum[N], g[N], gsum[N];
int main() {
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", a + i), sum += 1LL * a[i];
  if (sum % (1LL * (1 + n) * n / 2LL) != 0)
    return puts("NO"), 0;
  long long cs = sum / (1LL * (1 + n) * n / 2LL);
  for (long long i = 1; i <= n; i++) {
    long long nxt = i % n + 1;
    if ((a[nxt] - cs - a[i]) % n != 0 || a[i] + cs - a[nxt] < 0)
      return puts("NO"), 0;
    else
      b[nxt] = (a[i] - (a[nxt] - cs)) / n;
  }
  for (long long i = 1; i <= n; i++)
    f[i] = f[i - 1] + b[i], fsum[i] = fsum[i - 1] + b[i] * i;
  for (long long i = n; i >= 1; i--)
    g[i] = g[i + 1] + b[i], gsum[i] = gsum[i + 1] + b[i] * i;
  for (long long i = 1; i <= n; i++) {
    long long x =
        (i + 1) * f[i] - fsum[i] + (n + 1 + i) * g[i + 1] - gsum[i + 1];
    if (a[i] != x)
      return puts("NO"), 0;
  }
  puts("YES");
}

Fixed submission:
#include <bits/stdc++.h>
#define N 200006
using namespace std;
long long n, x, ans, a[N], b[N], p, sum, f[N], fsum[N], g[N], gsum[N];
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", a + i), sum += 1LL * a[i];
  if (sum % (1LL * (1 + n) * n / 2LL) != 0)
    return puts("NO"), 0;
  long long cs = sum / (1LL * (1 + n) * n / 2LL);
  for (long long i = 1; i <= n; i++) {
    long long nxt = i % n + 1;
    if ((a[nxt] - cs - a[i]) % n != 0 || a[i] + cs - a[nxt] < 0)
      return puts("NO"), 0;
    else
      b[nxt] = (a[i] - (a[nxt] - cs)) / n;
  }
  for (long long i = 1; i <= n; i++)
    f[i] = f[i - 1] + b[i], fsum[i] = fsum[i - 1] + b[i] * i;
  for (long long i = n; i >= 1; i--)
    g[i] = g[i + 1] + b[i], gsum[i] = gsum[i + 1] + b[i] * i;
  for (long long i = 1; i <= n; i++) {
    long long x =
        (i + 1) * f[i] - fsum[i] + (n + 1 + i) * g[i + 1] - gsum[i + 1];
    if (a[i] != x)
      return puts("NO"), 0;
  }
  puts("YES");
}
Problem p03809 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define int long long
#define inf 8938103643641919514ll
#define oku 1000000007ll
using namespace std;
int a, b, c, d, e, f, g, n, m;
int dx[] = {0, -1, 0, 1, 0};
int i, j, k;
struct A {
  int w;
  vector<int> e;
};
A p[100000];
int saiki(int oya, int u) {
  if (p[u].e.size() == 1)
    return p[u].w;
  int ma = -1, go = 0, ii = 0;
  for (auto x : p[u].e) {
    if (x == oya)
      continue;
    auto y = saiki(u, x);
    go += y;
    ma = max(ma, y);
    ii++;
  }
  if (ii == 1) {
    if (p[u].w != go)
      throw 'c';
    return p[u].w;
  }
  if (go < p[u].w || go > p[u].w * 2)
    throw 'a';
  int aa = (go - p[u].w);
  int bb = (ma > go / 2) ? (go - ma) : (go / 2);
  if (aa > bb)
    throw 'b';
  return p[u].w - aa;
}
int q[100000];
signed main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> p[i].w;
  }
  for (i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    p[u].e.push_back(v);
    p[v].e.push_back(u);
  }
  try {
    if (n == 2) {
      if (p[0].w != p[1].w)
        throw 'd';
    } else {
      for (i = 0; i < p[i].e.size() <= 1; i++)
        ;
      if (saiki(-1, i))
        throw 'e';
    }
    cout << "YES" << endl;
    return 0;
  } catch (char c) {
    cout << "NO" << endl;
    return 0;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define int long long
#define inf 8938103643641919514ll
#define oku 1000000007ll
using namespace std;
int a, b, c, d, e, f, g, n, m;
int dx[] = {0, -1, 0, 1, 0};
int i, j, k;
struct A {
  int w;
  vector<int> e;
};
A p[100000];
int saiki(int oya, int u) {
  if (p[u].e.size() == 1)
    return p[u].w;
  int ma = -1, go = 0, ii = 0;
  for (auto x : p[u].e) {
    if (x == oya)
      continue;
    auto y = saiki(u, x);
    go += y;
    ma = max(ma, y);
    ii++;
  }
  if (ii == 1) {
    if (p[u].w != go)
      throw 'c';
    return p[u].w;
  }
  if (go < p[u].w || go > p[u].w * 2)
    throw 'a';
  int aa = (go - p[u].w);
  int bb = (ma > go / 2) ? (go - ma) : (go / 2);
  if (aa > bb)
    throw 'b';
  return p[u].w - aa;
}
int q[100000];
signed main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> p[i].w;
  }
  for (i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    p[u].e.push_back(v);
    p[v].e.push_back(u);
  }
  try {
    if (n == 2) {
      if (p[0].w != p[1].w)
        throw 'd';
    } else {
      for (i = 0; p[i].e.size() <= 1; i++)
        ;
      if (saiki(-1, i))
        throw 'e';
    }
    cout << "YES" << endl;
    return 0;
  } catch (char c) {
    cout << "NO" << endl;
    return 0;
  }
}
Problem p03809 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#define SF scanf
#define PF printf
#define MAXN 100010
typedef long long ll;
using namespace std;
int n;
vector<int> a[MAXN];
ll val[MAXN];
int u, v;
ll dfs(int x, int fa) {
  ll sum = 0, mx = 0;
  if (a[x].size() == 1 && fa != 0)
    return val[x];
  for (int i = 0; i < int(a[x].size()); i++) {
    int u = a[x][i];
    if (u == fa)
      continue;
    ll s = dfs(u, x);
    mx = max(mx, s);
    sum += dfs(u, x);
  }
  if (sum < val[x] || sum > val[x] * 2) {
    PF("NO");
    exit(0);
  }
  ll nx = 2ll * val[x] - sum;
  if ((sum - nx) / 2ll < mx - nx) {
    PF("NO");
    exit(0);
  }
  return 2ll * val[x] - sum;
}
int main() {
  // freopen("tree.in","r",stdin);
  // freopen("tree.out","w",stdout);
  SF("%d", &n);
  for (int i = 1; i <= n; i++)
    SF("%lld", &val[i]);
  for (int i = 1; i < n; i++) {
    SF("%d%d", &u, &v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (a[i].size() == 1) {
      ans = (dfs(i, 0) == val[i]);
      break;
    }
  if (ans == 0)
    PF("NO");
  else
    PF("YES");
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#define SF scanf
#define PF printf
#define MAXN 100010
typedef long long ll;
using namespace std;
int n;
vector<int> a[MAXN];
ll val[MAXN];
int u, v;
ll dfs(int x, int fa) {
  ll sum = 0, mx = 0;
  if (a[x].size() == 1 && fa != 0)
    return val[x];
  for (int i = 0; i < int(a[x].size()); i++) {
    int u = a[x][i];
    if (u == fa)
      continue;
    ll s = dfs(u, x);
    mx = max(mx, s);
    sum += s;
  }
  if (sum < val[x] || sum > val[x] * 2) {
    PF("NO");
    exit(0);
  }
  ll nx = 2ll * val[x] - sum;
  if ((sum - nx) / 2ll < mx - nx) {
    PF("NO");
    exit(0);
  }
  return 2ll * val[x] - sum;
}
int main() {
  // freopen("tree.in","r",stdin);
  // freopen("tree.out","w",stdout);
  SF("%d", &n);
  for (int i = 1; i <= n; i++)
    SF("%lld", &val[i]);
  for (int i = 1; i < n; i++) {
    SF("%d%d", &u, &v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (a[i].size() == 1) {
      ans = (dfs(i, 0) == val[i]);
      break;
    }
  if (ans == 0)
    PF("NO");
  else
    PF("YES");
}
Problem p03809 (C++)

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

using namespace std;
typedef long long ll;

#define MAX 100001
int A[MAX];
vector<int> v[MAX];

void dfs(int root, int parent) {
  if (v[root].size() == 1)
    return;

  ll mx = -1, sum = -A[root];
  for (int vv : v[root]) {
    if (vv != parent) {
      dfs(vv, root);
      sum += A[vv];
      if (mx < A[vv])
        mx = A[vv];
    }
  }
  if (sum < 0 || A[root] < mx || (A[root] -= sum) < 0)
    puts("NO"), exit(0);
}

int main(void) {
  int i, n, a, b, root;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", A + i);
  if (n == 2)
    return puts(A[0] == 1 && A[1] == 1 ? "NO" : "YES");
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    v[a - 1].emplace_back(b - 1);
    v[b - 1].emplace_back(a - 1);
  }
  for (root = 0; root < n; root++) {
    if (v[root].size() > 1) {
      dfs(root, -1);
      break;
    }
  }
  puts(A[root] ? "NO" : "YES");
  return 0;
}


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

using namespace std;
typedef long long ll;

#define MAX 100001
int A[MAX];
vector<int> v[MAX];

void dfs(int root, int parent) {
  if (v[root].size() == 1)
    return;

  ll mx = -1, sum = -A[root];
  for (int vv : v[root]) {
    if (vv != parent) {
      dfs(vv, root);
      sum += A[vv];
      if (mx < A[vv])
        mx = A[vv];
    }
  }
  if (sum < 0 || A[root] < mx || (A[root] -= sum) < 0)
    puts("NO"), exit(0);
}

int main(void) {
  int i, n, a, b, root;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", A + i);
  if (n == 2)
    return puts(A[0] == 1 && A[1] == 1 ? "YES" : "NO"), 0;
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    v[a - 1].emplace_back(b - 1);
    v[b - 1].emplace_back(a - 1);
  }
  for (root = 0; root < n; root++) {
    if (v[root].size() > 1) {
      dfs(root, -1);
      break;
    }
  }
  puts(A[root] ? "NO" : "YES");
  return 0;
}
Problem p03809 (C++)

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

// template
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;
const double eps = 1e-12;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// end

int n, a[101010];
vector<int> g[101010];

int dfs(int v, int p) {
  if (g[v].size() == 1)
    return a[v];
  vector<int> cs;
  int sum = 0;
  for (int t : g[v])
    if (t != p) {
      int c = dfs(t, v);
      cs.push_back(c);
      sum += c;
    }
  ll x = 2 * a[v] - sum, y = (sum - x) / 2;
  if (((sum - x) & 1) or y < 0) {
    puts("NO");
    exit(0);
  }
  int ma = *max_element(ALL(cs));
  if (min(sum - ma, sum / 2) < y) {
    puts("NO");
    exit(0);
  }
  return x;
}

int main() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n - 1) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if (n == 2) {
    printf(a[0] == a[1] ? "YES" : "NO");
  }
  int r = -1;
  rep(i, 0, n) if (g[i].size() > 1) {
    r = i;
    break;
  }
  int res = dfs(r, -1);
  printf(res == 0 ? "YES" : "NO");
  return 0;
}


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

// template
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;
const double eps = 1e-12;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// end

int n, a[101010];
vector<int> g[101010];

int dfs(int v, int p) {
  if (g[v].size() == 1)
    return a[v];
  vector<int> cs;
  int sum = 0;
  for (int t : g[v])
    if (t != p) {
      int c = dfs(t, v);
      cs.push_back(c);
      sum += c;
    }
  ll x = 2 * a[v] - sum, y = (sum - x) / 2;
  if (((sum - x) & 1) or y < 0) {
    puts("NO");
    exit(0);
  }
  int ma = *max_element(ALL(cs));
  if (min(sum - ma, sum / 2) < y) {
    puts("NO");
    exit(0);
  }
  return x;
}

int main() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n - 1) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if (n == 2) {
    printf(a[0] == a[1] ? "YES" : "NO");
    return 0;
  }
  int r = -1;
  rep(i, 0, n) if (g[i].size() > 1) {
    r = i;
    break;
  }
  int res = dfs(r, -1);
  printf(res == 0 ? "YES" : "NO");
  return 0;
}
Problem p03809 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int n;
ll a[100005];
vector<int> edge[100005];
bool flag = true;
ll dfs(int v, int u, int d) {
  if (edge[v].size() == 1)
    return a[v];
  ll cnt = 0, mx = 0;
  rep(i, edge[v].size()) {
    if (edge[v][i] == u)
      continue;
    ll A = dfs(edge[v][i], v, d + 1);
    cnt += A;
    mx = max(mx, A);
  }
  ll pr = 0;
  if (mx * 2 > cnt) {
    pr = cnt - mx;
  } else {
    pr = cnt / 2;
  }
  if (d == 0) {
    if (pr * 2 != cnt || a[v] != pr)
      flag = false;
  } else {
    if (cnt - pr <= a[v] && a[v] <= cnt)
      ;
    else
      flag = false;
  }
  return cnt - (cnt - a[v]) * 2LL;
}
int main() {
  cin >> n;
  repn(i, n) cin >> a[i];
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  int v = -1;
  repn(i, n) {
    if (edge[i].size() >= 2) {
      v = i;
      break;
    }
  }
  dfs(v, -1, 0);
  puts(!flag ? "NO" : "YES");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int n;
ll a[100005];
vector<int> edge[100005];
bool flag = true;
ll dfs(int v, int u, int d) {
  if (edge[v].size() == 1)
    return a[v];
  ll cnt = 0, mx = 0;
  rep(i, edge[v].size()) {
    if (edge[v][i] == u)
      continue;
    ll A = dfs(edge[v][i], v, d + 1);
    cnt += A;
    mx = max(mx, A);
  }
  ll pr = 0;
  if (mx * 2 > cnt) {
    pr = cnt - mx;
  } else {
    pr = cnt / 2;
  }
  if (d == 0) {
    if (pr * 2 != cnt || a[v] != pr)
      flag = false;
  } else {
    if (cnt - pr <= a[v] && a[v] <= cnt)
      ;
    else
      flag = false;
  }
  return cnt - (cnt - a[v]) * 2LL;
}
int main() {
  cin >> n;
  repn(i, n) cin >> a[i];
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  if (n == 2) {
    puts(a[1] != a[2] ? "NO" : "YES");
    return 0;
  }
  int v = -1;
  repn(i, n) {
    if (edge[i].size() >= 2) {
      v = i;
      break;
    }
  }
  dfs(v, -1, 0);
  puts(!flag ? "NO" : "YES");
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int a[100005], n;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
bool check() {
  int m = 0;
  for (int i = 1; i <= n; i++)
    m += a[i] & 1;
  if ((n - m) & 1)
    return 1;
  if (m > 1)
    return 0;
  int d = 0;
  for (int i = 1; i <= n; i++) {
    a[i] ^= a[i] & 1;
    d = gcd(d, a[i]);
  }
  for (int i = 1; i <= n; i++)
    a[i] /= d;
  return check() ^ 1;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (check())
    printf("First\n");
  else
    printf("Second\n");
}

Fixed submission:
#include <cstdio>
int a[100005], n;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
bool check() {
  int m = 0;
  for (int i = 1; i <= n; i++)
    m += a[i] & 1;
  if ((n - m) & 1)
    return 1;
  if (m > 1)
    return 0;
  int d = 0;
  for (int i = 1; i <= n; i++) {
    a[i] ^= a[i] & 1;
    if (!a[i])
      return 0;
    d = gcd(d, a[i]);
  }
  for (int i = 1; i <= n; i++)
    a[i] /= d;
  return check() ^ 1;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (check())
    printf("First\n");
  else
    printf("Second\n");
}
Problem p03810 (C++)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define N 2010
int n;
int a[N];

void end(int x) {
  if (x == 1)
    puts("First");
  else
    puts("Second");
  exit(0);
}

int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int x = 1;
  while (true) {
    ll S = 0;
    int odd = 0;
    int F1 = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] & 1)
        odd++;
      S += a[i];
      if (a[i] == 1)
        F1++;
    }
    if ((S - n) % 2 == 1)
      end(x);
    if (odd >= 2 || F1 > 0)
      end(3 - x);
    int g = 0;
    for (int i = 0; i < n; i++)
      if (a[i] & 1)
        g = gcd(g, a[i] - 1);
      else
        g = gcd(g, a[i]);
    for (int i = 0; i < n; i++)
      a[i] /= g;
    x = 3 - x;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define N 100010
int n;
int a[N];

void end(int x) {
  if (x == 1)
    puts("First");
  else
    puts("Second");
  exit(0);
}

int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int x = 1;
  while (true) {
    ll S = 0;
    int odd = 0;
    int F1 = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] & 1)
        odd++;
      S += a[i];
      if (a[i] == 1)
        F1++;
    }
    if ((S - n) % 2 == 1)
      end(x);
    if (odd >= 2 || F1 > 0)
      end(3 - x);
    int g = 0;
    for (int i = 0; i < n; i++)
      if (a[i] & 1)
        g = gcd(g, a[i] - 1);
      else
        g = gcd(g, a[i]);
    for (int i = 0; i < n; i++)
      a[i] /= g;
    x = 3 - x;
  }
  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
//                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

const int N = 3e5 + 100, OO = 1e16, T = 4500 + 100, M = 1e9 + 7, P = 6151,
          SQ = 280, lg = 30;
typedef pair<int, int> pii;
int n, a[N];

bool check() {
  int od, ev;
  od = ev = 0;
  for (int i = 0; i < n; i++)
    od += (a[i] % 2), ev += ((a[i] + 1) % 2);
  if (ev % 2 == 1)
    return true;
  if (od > 1)
    return false;
  int gc = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 1)
      a[i]--;
    gc = __gcd(a[i], gc);
  }
  for (int i = 0; i < n; i++)
    a[i] /= gc;
  return !check();
}

int32_t main() {
  use_fast;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (check())
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


Fixed submission:
//                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

const int N = 3e5 + 100, OO = 1e16, T = 4500 + 100, M = 1e9 + 7, P = 6151,
          SQ = 280, lg = 30;
typedef pair<int, int> pii;
int n, a[N];

bool check() {
  int od, ev, sum;
  od = ev = sum = 0;
  bool b = false;
  for (int i = 0; i < n; i++) {
    sum += a[i] - 1;
    if (a[i] == 1)
      b = true;
  }
  if (b) {
    if (sum % 2)
      return true;
    return false;
  }
  for (int i = 0; i < n; i++)
    od += (a[i] % 2), ev += ((a[i] + 1) % 2);
  if (ev % 2 == 1)
    return true;
  if (od > 1)
    return false;
  int gc = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 1)
      a[i]--;
    gc = __gcd(a[i], gc);
  }
  for (int i = 0; i < n; i++)
    a[i] /= gc;
  return !check();
}

int32_t main() {
  use_fast;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (check())
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define ll long long
#define REP(a, b, c) for (int a = b; a <= c; a++)
#define re register
#define file(a)                                                                \
  freopen(a ".in", "r", stdin);                                                \
  freopen(a ".out", "w", stdout)
typedef pair<int, int> pii;
#define mp make_pair
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 100010, Inf = 1e9 + 10;
int n, A[N];
int Solve(int b) {
  int s = 0, mn = Inf;
  for (int i = 1; i <= n; i++)
    s += A[i] & 1, mn = min(mn, A[i]);
  if ((n - s) & 1)
    return b;
  if (s > 1 && mn == 1)
    return b ^ 1;
  int d = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] & 1)
      A[i]--;
    d = __gcd(A[i], d);
  }
  for (int i = 1; i <= n; i++)
    A[i] /= d;
  return Solve(b ^ 1);
}
int main() {
  n = gi();
  for (int i = 1; i <= n; i++)
    A[i] = gi();
  puts(Solve(1) ? "First" : "Second");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define ll long long
#define REP(a, b, c) for (int a = b; a <= c; a++)
#define re register
#define file(a)                                                                \
  freopen(a ".in", "r", stdin);                                                \
  freopen(a ".out", "w", stdout)
typedef pair<int, int> pii;
#define mp make_pair
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 100010, Inf = 1e9 + 10;
int n, A[N];
int Solve(int b) {
  int s = 0, mn = Inf;
  for (int i = 1; i <= n; i++)
    s += A[i] & 1, mn = min(mn, A[i]);
  if ((n - s) & 1)
    return b;
  if (s > 1 || mn == 1)
    return b ^ 1;
  int d = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] & 1)
      A[i]--;
    d = __gcd(A[i], d);
  }
  for (int i = 1; i <= n; i++)
    A[i] /= d;
  return Solve(b ^ 1);
}
int main() {
  n = gi();
  for (int i = 1; i <= n; i++)
    A[i] = gi();
  puts(Solve(1) ? "First" : "Second");
  return 0;
}
Problem p03810 (C++)

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for (int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for (int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

bool win(const vector<int> &v) {
  int evens = 0;
  for (auto &each : v) {
    evens += each % 2 == 0;
  }
  if (evens & 1) {
    return true;
  } else if ((int)v.size() - evens == 1) {
    vector<int> next_v = v;
    int gc = 0;
    for (auto &each : next_v) {
      if (each & 1) {
        each--;
      }
      gc = gcd(gc, each);
    }
    for (auto &each : next_v) {
      each /= gc;
    }
    return !win(next_v);
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> v(n);
  fori(i, 0, n) { cin >> v[i]; }

  cout << (win(v) ? "First" : "Second") << '\n';

  return 0;
}


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for (int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for (int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

bool win(const vector<int> &v) {
  int evens = 0;
  for (auto &each : v) {
    evens += each % 2 == 0;
  }
  if (evens & 1) {
    return true;
  } else if ((int)v.size() - evens == 1) {
    vector<int> next_v = v;
    int gc = 0;
    for (auto &each : next_v) {
      if (each & 1) {
        if (each == 1) {
          return false;
        }
        each--;
      }
      gc = gcd(gc, each);
    }
    for (auto &each : next_v) {
      each /= gc;
    }
    return !win(next_v);
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> v(n);
  fori(i, 0, n) { cin >> v[i]; }

  cout << (win(v) ? "First" : "Second") << '\n';

  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, v[100002];
int winn(int turn) {
  int odd = 0, even = 0;
  for (int i = 1; i <= n; ++i) {
    if (v[i] % 2 == 0)
      ++even;
    else if (v[i] == 1)
      ++odd;
  }
  if (even % 2 == 1)
    return turn;
  if (even < n - 1)
    return 3 - turn;
  //  if(odd)
  //    return 3 - turn;
  for (int i = 1; i <= n; ++i)
    if (v[i] % 2 == 1)
      --v[i];
  int cmm = v[1];
  for (int i = 1; i <= n; ++i)
    cmm = __gcd(cmm, v[i]);
  for (int i = 1; i <= n; ++i)
    v[i] /= cmm;
  return winn(3 - turn);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> v[i];
  int tu = winn(1);
  if (tu == 1)
    cout << "First";
  else
    cout << "Second";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, v[100002];
int winn(int turn) {
  int odd = 0, even = 0;
  for (int i = 1; i <= n; ++i) {
    if (v[i] % 2 == 0)
      ++even;
    else if (v[i] == 1)
      ++odd;
  }
  if (even % 2 == 1)
    return turn;
  if (even < n - 1)
    return 3 - turn;
  if (odd)
    return 3 - turn;
  for (int i = 1; i <= n; ++i)
    if (v[i] % 2 == 1)
      --v[i];
  int cmm = v[1];
  for (int i = 1; i <= n; ++i)
    cmm = __gcd(cmm, v[i]);
  for (int i = 1; i <= n; ++i)
    v[i] /= cmm;
  return winn(3 - turn);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> v[i];
  int tu = winn(1);
  if (tu == 1)
    cout << "First";
  else
    cout << "Second";
  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 100010
int n, k, a[MAXN];
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int g;; k ^= 1) {
    int count = 0;
    for (int i = 1; i <= n; i++)
      count += a[i] & 1;
    if ((n - count) & 1) {
      return puts(k ? "Second" : "First"), 0;
    }
    if (count >= 2) {
      return puts(k ? "First" : "Second"), 0;
    }
    g = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] & 1) {
        if (a[i] == 1)
          return puts(k ? "First" : "Second");
        --a[i];
      }
      g = gcd(a[i], g);
    }
    for (int i = 1; i <= n; i++)
      a[i] /= g;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 100010
int n, k, a[MAXN];
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int g;; k ^= 1) {
    int count = 0;
    for (int i = 1; i <= n; i++)
      count += a[i] & 1;
    if ((n - count) & 1) {
      return puts(k ? "Second" : "First"), 0;
    }
    if (count >= 2) {
      return puts(k ? "First" : "Second"), 0;
    }
    g = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] & 1) {
        if (a[i] == 1)
          return puts(k ? "First" : "Second"), 0;
        --a[i];
      }
      g = gcd(a[i], g);
    }
    for (int i = 1; i <= n; i++)
      a[i] /= g;
  }
  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[100005], n;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void haowuliaokuaixiake(int f) {
  int x = 0, y = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] & 1)
      x++;
    else
      y++;
  if (y & 1) {
    if (f == 1)
      printf("First\n");
    else
      printf("Second\n");
    return;
  }
  if (x > 1) {
    if (f == 1)
      printf("Second\n");
    else
      printf("First\n");
    return;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] & 1)
      a[i]--;
  int g = a[1];
  for (int i = 2; i <= n; i++)
    g = gcd(g, a[i]);
  for (int i = 1; i <= n; i++)
    a[i] /= g;
  haowuliaokuaixiake(-f);
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  haowuliaokuaixiake(1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[100005], n;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void haowuliaokuaixiake(int f) {
  int x = 0, y = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] & 1)
      x++;
    else
      y++;
  if (y & 1) {
    if (f == 1)
      printf("First\n");
    else
      printf("Second\n");
    return;
  }
  if (x > 1) {
    if (f == 1)
      printf("Second\n");
    else
      printf("First\n");
    return;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      if (f == 1)
        printf("Second\n");
      else
        printf("First\n");
      return;
    }
  for (int i = 1; i <= n; i++)
    if (a[i] & 1)
      a[i]--;
  int g = a[1];
  for (int i = 2; i <= n; i++)
    g = gcd(g, a[i]);
  for (int i = 1; i <= n; i++)
    a[i] /= g;
  haowuliaokuaixiake(-f);
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  haowuliaokuaixiake(1);
  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)
using ll = long long;
using namespace std;
int gcd(int a, int b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}
bool solve(int n, vector<int> &a) {
  ll sum = whole(accumulate, a, 0ll);
  bool is_first = (sum - n) % 2;
  int even = whole(count_if, a, [&](int ai) { return ai % 2 == 0; });
  if (not is_first and even == n - 1) {
    auto it = whole(find_if, a, [&](int ai) { return ai % 2 == 1; });
    --(*it);
    int d = a[0];
    repeat(i, n) d = gcd(d, a[i]);
    repeat(i, n) a[i] /= d;
    return not solve(n, a);
  } else {
    return is_first;
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  repeat(i, n) cin >> a[i];
  cout << (solve(n, a) ? "First" : "Second") << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)
using ll = long long;
using namespace std;
int gcd(int a, int b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}
bool solve(int n, vector<int> &a) {
  ll sum = whole(accumulate, a, 0ll);
  bool is_first = (sum - n) % 2;
  int even = whole(count_if, a, [&](int ai) { return ai % 2 == 0; });
  auto odd = whole(find_if, a, [&](int ai) { return ai % 2 == 1; });
  if (not is_first and even == n - 1 and *odd != 1) {
    --(*odd);
    int d = a[0];
    repeat(i, n) d = gcd(d, a[i]);
    repeat(i, n) a[i] /= d;
    return not solve(n, a);
  } else {
    return is_first;
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  repeat(i, n) cin >> a[i];
  cout << (solve(n, a) ? "First" : "Second") << endl;
  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define fo(i, a, b) for (ll i = a; i <= b; i++)
#define fd(i, a, b) for (ll i = a; i >= b; i--)
#define N 101000
#define ll long long
using namespace std;
ll sum, n, a[N], g1[N], g2[N];
ll gcd(ll x, ll y) {
  if (x == -1 || y == -1)
    return -x * y;
  return y == 0 ? x : gcd(y, x % y);
}
ll dg(ll x) {
  g1[1] = a[1];
  g2[n] = a[n];
  g1[0] = g2[n + 1] = -1;
  fo(i, 2, n) g1[i] = gcd(g1[i - 1], a[i]);
  fd(i, n - 1, 1) g2[i] = gcd(g2[i + 1], a[i]);
  ll gd = -1, k = 0;
  fo(i, 1, n) {
    gd = gcd(gcd(a[i] - 1, g1[i - 1]), g2[i + 1]);
    k = i;
    if (((sum - 1) / gd) % 2 == 1)
      break;
    gd = -1;
  }
  if (gd != -1) {
    fo(i, 1, n) if (i != k) a[i] = a[i] / gd;
    a[k] = (a[k] - 1) / gd;
    sum = (sum - 1) / (ll)gd;
    return 1 - dg(x ^ 1);
  }
  return 0;
}
int main() {
  scanf("%lld", &n);
  fo(i, 1, n) scanf("%lld", &a[i]), sum += (ll)a[i];
  if (n % 2 == 0) {
    if (sum % 2 == 1)
      printf("First\n");
    else
      printf("Second\n");
    return 0;
  }
  if (sum % 2 == 0)
    return printf("First\n"), 0;
  if (dg(1) == 1)
    printf("First\n");
  else
    printf("Second\n");
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define fo(i, a, b) for (ll i = a; i <= b; i++)
#define fd(i, a, b) for (ll i = a; i >= b; i--)
#define N 101000
#define ll long long
using namespace std;
ll sum, n, a[N], g1[N], g2[N];
ll gcd(ll x, ll y) {
  if (x == -1 || y == -1)
    return -x * y;
  return y == 0 ? x : gcd(y, x % y);
}
ll dg(ll x) {
  g1[1] = a[1];
  g2[n] = a[n];
  g1[0] = g2[n + 1] = -1;
  fo(i, 2, n) g1[i] = gcd(g1[i - 1], a[i]);
  fd(i, n - 1, 1) g2[i] = gcd(g2[i + 1], a[i]);
  ll gd = -1, k = 0;
  fo(i, 1, n) if (a[i] != 1) {
    gd = gcd(gcd(a[i] - 1, g1[i - 1]), g2[i + 1]);
    k = i;
    if (((sum - 1) / gd) % 2 == 1)
      break;
    gd = -1;
  }
  if (gd != -1) {
    fo(i, 1, n) if (i != k) a[i] = a[i] / gd;
    a[k] = (a[k] - 1) / gd;
    sum = (sum - 1) / (ll)gd;
    return 1 - dg(x ^ 1);
  }
  return 0;
}
int main() {
  scanf("%lld", &n);
  fo(i, 1, n) scanf("%lld", &a[i]), sum += (ll)a[i];
  if (n % 2 == 0) {
    if (sum % 2 == 1)
      printf("First\n");
    else
      printf("Second\n");
    return 0;
  }
  if (sum % 2 == 0)
    return printf("First\n"), 0;
  if (dg(1) == 1)
    printf("First\n");
  else
    printf("Second\n");
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  // freopen("AGC010-D.in", "r", stdin);
  int n, cur = 0;
  cin >> n;
  vector<int> arr(n);
  copy(istream_iterator<int>(cin), istream_iterator<int>(), arr.begin());
  string str[] = {"First", "Second"}, ans;
  while (ans.empty()) {
    int cnt =
        count_if(arr.begin(), arr.end(), [&](int x) { return x % 2 == 0; });
    if (cnt & 1) {
      ans = str[cur];
      break;
    }
    cur ^= 1;
    if (cnt != n - 1) {
      ans = str[cur];
    }
    int g = 0;
    for_each(arr.begin(), arr.end(), [&](int x) {
      if (x == 1) {
        ans = str[cur];
      }
      x -= x & 1;
      while (x) {
        int r = g % x;
        g = x;
        x = r;
      }
    });
    for_each(arr.begin(), arr.end(), [&](int &x) { x /= g; });
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // freopen("AGC010-D.in", "r", stdin);
  int n, cur = 0;
  cin >> n;
  vector<int> arr(n);
  copy(istream_iterator<int>(cin), istream_iterator<int>(), arr.begin());
  string str[] = {"First", "Second"}, ans;
  while (ans.empty()) {
    int cnt =
        count_if(arr.begin(), arr.end(), [&](int x) { return x % 2 == 0; });
    if (cnt & 1) {
      ans = str[cur];
      break;
    }
    cur ^= 1;
    if (cnt != n - 1) {
      ans = str[cur];
    }
    int g = 0;
    for_each(arr.begin(), arr.end(), [&](int x) {
      if (x == 1) {
        ans = str[cur];
      }
      x -= x & 1;
      while (x) {
        int r = g % x;
        g = x;
        x = r;
      }
    });
    if (!g) {
      break;
    }
    for_each(arr.begin(), arr.end(), [&](int &x) { x /= g; });
  }
  cout << ans << endl;
  return 0;
}
Problem p03810 (C++)

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

const int N = 100005;
int n, a[N];
bool solve() {
  int odd = 0, even = 0, g = 0;
  for (int i = 1; i <= n; ++i)
    ++(a[i] & 1 ? odd : even);
  if (even & 1)
    return 1;
  if (odd > 1)
    return 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] & 1)
      --a[i];
  for (int i = 1; i <= n; ++i)
    g = std::__gcd(g, a[i]);
  for (int i = 1; i <= n; ++i)
    a[i] /= g;
  return !solve();
}

int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n;
  for (int i = 1; i <= n; ++i)
    std::cin >> a[i];
  std::cout << (solve() ? "First" : "Second") << '\n';
  return 0;
}

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

const int N = 100005;
int n, a[N];
bool solve() {
  int odd = 0, even = 0, g = 0;
  for (int i = 1; i <= n; ++i)
    ++(a[i] & 1 ? odd : even);
  if (even & 1)
    return 1;
  if (odd > 1)
    return 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] == 1)
      return 0;
    else if (a[i] & 1)
      --a[i];
  for (int i = 1; i <= n; ++i)
    g = std::__gcd(g, a[i]);
  for (int i = 1; i <= n; ++i)
    a[i] /= g;
  return !solve();
}

int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n;
  for (int i = 1; i <= n; ++i)
    std::cin >> a[i];
  std::cout << (solve() ? "First" : "Second") << '\n';
  return 0;
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout << x << '\n', 0;
using namespace std;
ll solve(vector<int> a) {
  ll p0 = 0, p1 = 0;
  for (auto u : a) {
    if (u % 2 == 1)
      p1++;
    else
      p0++;
  }
  if (p0 % 2 == 1)
    return 1;
  if (p1 != 1)
    return 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] % 2 == 1)
      a[i]--;
  }
  ll w = 0;
  for (auto u : a)
    w = __gcd(w, u);
  for (int i = 0; i < a.size(); i++)
    a[i] /= w;
  return 1 - solve(a);
}
int32_t main() {
  ll n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.pb(x);
  }
  ll ans = solve(a);
  if (ans)
    kill("First");
  kill("Second");
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout << x << '\n', 0;
using namespace std;
ll solve(vector<int> a) {
  ll p0 = 0, p1 = 0;
  for (auto u : a) {
    if (u % 2 == 1)
      p1++;
    else
      p0++;
  }
  if (p0 % 2 == 1)
    return 1;
  if (p1 != 1)
    return 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] % 2 == 1)
      a[i]--;
    if (a[i] == 0)
      return 0;
  }
  ll w = 0;
  for (auto u : a)
    w = __gcd(w, u);
  for (int i = 0; i < a.size(); i++)
    a[i] /= w;
  return 1 - solve(a);
}
int32_t main() {
  ll n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.pb(x);
  }
  ll ans = solve(a);
  if (ans)
    kill("First");
  kill("Second");
}
Problem p03810 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
bool f(vector<int> &A) {
  int N = A.size();
  int even = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] % 2 == 0)
      even++;
  }
  if (even % 2 == 1)
    return false;
  if (even == N - 1) {
    for (int i = 0; i < N; i++)
      if (A[i] % 2) {
        A[i]--;
        int t = A[0];
        for (auto a : A)
          t = __gcd(t, a);
        for (auto &a : A)
          a /= t;
        bool ok = false;
        if (f(A))
          ok = true;
        for (auto &a : A)
          a *= t;
        A[i]++;
        if (ok)
          return false;
      }
  }
  return true;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A)
    cin >> a;
  cout << (!f(A) ? "First" : "Second") << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
bool f(vector<int> &A) {
  int N = A.size();
  int even = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] % 2 == 0)
      even++;
  }
  if (even % 2 == 1)
    return false;
  if (even == N - 1) {
    for (int i = 0; i < N; i++)
      if (A[i] % 2 && A[i] >= 2) {
        A[i]--;
        int t = A[0];
        for (auto a : A)
          t = __gcd(t, a);
        for (auto &a : A)
          a /= t;
        bool ok = false;
        if (f(A))
          ok = true;
        for (auto &a : A)
          a *= t;
        A[i]++;
        if (ok)
          return false;
      }
  }
  return true;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A)
    cin >> a;
  cout << (!f(A) ? "First" : "Second") << '\n';
  return 0;
}
Problem p03810 (C++)

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

const int N = 1e5 + 10;

int n, A[N];

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

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

bool Dfs(int f) {
  int odd = 0, fl = 1;
  for (int j = 1; j <= n; ++j) {
    if (A[j] & 1)
      odd++;
    if (A[j] == 1)
      fl = 0;
  }
  if (odd >= 2 && !((n - odd) & 1))
    return f ^ 1;
  if (odd >= 1 && (n - odd) & 1)
    return f;
  if (!fl && (n - odd) & 1)
    return f;
  for (int j = 1; j <= n; ++j)
    if (A[j] & 1) {
      A[j]--;
      break;
    }
  int g = A[1];
  for (int j = 2; j <= n; ++j)
    g = gcd(g, A[j]);
  for (int j = 1; j <= n; ++j)
    A[j] /= g;
  return Dfs(f ^ 1);
}

void Solve() {
  if (Dfs(1))
    printf("First\n");
  else
    printf("Second\n");
}

int main() {
  Init();
  Solve();
  return 0;
}

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

const int N = 1e5 + 10;

int n, A[N];

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

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

bool Dfs(int f) {
  int odd = 0, fl = 1;
  for (int j = 1; j <= n; ++j) {
    if (A[j] & 1)
      odd++;
    if (A[j] == 1)
      fl = 0;
  }
  if (odd >= 2 && !((n - odd) & 1))
    return f ^ 1;
  if (odd >= 1 && (n - odd) & 1)
    return f;
  if (!fl)
    return (n - odd) & 1;
  for (int j = 1; j <= n; ++j)
    if (A[j] & 1) {
      A[j]--;
      break;
    }
  int g = A[1];
  for (int j = 2; j <= n; ++j)
    g = gcd(g, A[j]);
  for (int j = 1; j <= n; ++j)
    A[j] /= g;
  return Dfs(f ^ 1);
}

void Solve() {
  if (Dfs(1))
    printf("First\n");
  else
    printf("Second\n");
}

int main() {
  Init();
  Solve();
  return 0;
}