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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  set<int> food, likefood[M];
  int A[N][M], K[N];
  for (int i = 0; i < N; i++) {
    cin >> K[i];
    for (int k = 0; k < K[i]; k++) {
      cin >> A[i][k];
      likefood[i].insert(A[i][k]);
    }
  }
  for (int i = 1; i <= M; i++)
    food.insert(i);
  for (int i = 0; i < N; i++) {
    for (int f = 1; f <= M; f++) {
      if (likefood[i].count(f) == 0)
        food.erase(f);
    }
  }
  cout << food.size() << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  set<int> food, likefood[N];
  int A[N][M], K[N];
  for (int i = 0; i < N; i++) {
    cin >> K[i];
    for (int k = 0; k < K[i]; k++) {
      cin >> A[i][k];
      likefood[i].insert(A[i][k]);
    }
  }
  for (int i = 1; i <= M; i++)
    food.insert(i);
  for (int i = 0; i < N; i++) {
    for (int f = 1; f <= M; f++) {
      if (likefood[i].count(f) == 0)
        food.erase(f);
    }
  }
  cout << food.size() << endl;
  return 0;
}
Problem p03126 (C++)

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

int main() {

  int N, M;
  cin >> N >> M;

  vector<vector<bool>> A(M, vector<bool>(M, false));

  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int a;
      cin >> a;
      A[i][a - 1] = true;
    }
  }

  int ans = 0;

  for (int i = 0; i < M; i++) {
    bool judge = true;
    for (int j = 0; j < N; j++) {
      judge &= A[j][i];
    }

    if (judge) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {

  int N, M;
  cin >> N >> M;

  vector<vector<bool>> A(N, vector<bool>(M, false));

  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int a;
      cin >> a;
      A[i][a - 1] = true;
    }
  }

  int ans = 0;

  for (int i = 0; i < M; i++) {
    bool judge = true;
    for (int j = 0; j < N; j++) {
      judge &= A[j][i];
    }

    if (judge) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03126 (C++)

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

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> data(n, vector<int>(m));
  vector<int> like(m);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i).at(0);
    for (int j = 0; j < data.at(i).at(0); j++) {
      cin >> data.at(i).at(j + 1);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < data.at(i).at(0); j++) {
      like.at(data.at(i).at(j + 1) - 1)++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (like.at(i) == n)
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> data(n * m, vector<int>(n * m));
  vector<int> like(m * n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i).at(0);
    for (int j = 0; j < data.at(i).at(0); j++) {
      cin >> data.at(i).at(j + 1);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < data.at(i).at(0); j++) {
      like.at(data.at(i).at(j + 1) - 1)++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (like.at(i) == n)
      ans++;
  }
  cout << ans << endl;
}
Problem p03126 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(m, 0);
  int k, a;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> a;
      v.at(a - 1)++;
    }
  }

  sort(v.begin(), v.end());
  int i = m - 1, ans = 0;
  while (v.at(i) == n && i >= 0) {
    ans++;
    i--;
  }
  cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(m, 0);
  int k, a;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> a;
      v.at(a - 1)++;
    }
  }

  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (v.at(i) == n) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03126 (C++)

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

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> vec(b);
  for (ll i = 0; i < a; i++) {
    ll c;
    cin >> c;
    for (ll j = 0; i < c; j++) {
      ll d;
      cin >> d;
      vec.at(d - 1) += 1;
    }
  }
  ll e = 0;
  for (ll i = 0; i < b; i++) {
    if (vec.at(i) == a) {
      e += 1;
    }
  }
  cout << e << endl;

  return 0;
}


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

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> vec(b);
  for (ll i = 0; i < a; i++) {
    ll c;
    cin >> c;
    for (ll j = 0; j < c; j++) {
      ll d;
      cin >> d;
      vec.at(d - 1) += 1;
    }
  }
  ll e = 0;
  for (ll i = 0; i < b; i++) {
    if (vec.at(i) == a) {
      e += 1;
    }
  }
  cout << e << endl;

  return 0;
}
Problem p03126 (C++)

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

int main() {
  int a, b, d, e;
  cin >> a >> b;
  vector<int> c(b, 0);
  for (int i = 0; i < a; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> e;
      c.at(e - 1)++;
    }
  }
  int count = 0;
  for (int i = 0; i < b; b++) {
    if (c.at(i) == a)
      count++;
  }
  cout << count << endl;
}


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

int main() {
  int a, b, d, e;
  cin >> a >> b;
  vector<int> c(b, 0);
  for (int i = 0; i < a; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> e;
      c.at(e - 1)++;
    }
  }
  int count;
  for (int i = 0; i < b; i++) {
    if (c.at(i) == a)
      count++;
  }
  cout << count << endl;
}
Problem p03127 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll N;
  cin >> N;
  vector<ll> hp(N, 0);
  rep(i, N) { cin >> hp[i]; }
  sort(hp.begin(), hp.end());
  ll min = hp[0];
  rep(i, N) {
    rep(j, N) {
      ll ret = gcd(hp[i], hp[j]);
      if (ret != 0 & min > ret) {
        min = ret;
      }
    }
  }
  cout << min << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll N;
  cin >> N;
  vector<ll> hp(N, 0);
  rep(i, N) { cin >> hp[i]; }
  sort(hp.begin(), hp.end());
  ll min = hp[0];
  rep(i, N - 1) {
    ll ret = gcd(min, hp[i + 1]);
    if (ret != 0 & ret < min) {
      min = ret;
    }
  }
  cout << min << endl;
  return 0;
}
Problem p03127 (C++)

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

using namespace std;

int main() {

  int n;
  cin >> n;

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

  int min;
  min = a[0];
  for (int i = 1; i < n; i++) {
    if (min > a[i]) {
      min = a[i];
    }
  }

  int co = 1;

  for (int i = min; i > 2; i--) {
    bool flag = true;
    for (int k = 0; k < n; k++) {
      if (a[k] % i != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      co = i;
      break;
    }
  }
  if (co == 1) {
    bool flag = true;
    for (int k = 0; k < n; k++) {
      if (a[k] % 2 != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      co = 2;
    }
  }
  cout << co << endl;

  return 0;
}


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

using namespace std;

int main() {

  int n;
  cin >> n;

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

  int min;
  min = a[0];
  for (int i = 1; i < n; i++) {
    if (min > a[i]) {
      min = a[i];
    }
  }

  int co = 1;

  for (int i = min; i > 2; i -= 2) {
    bool flag = true;
    for (int k = 0; k < n; k++) {
      if (a[k] % i != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      co = i;
      break;
    }
  }
  if (co == 1) {
    bool flag = true;
    for (int k = 0; k < n; k++) {
      if (a[k] % 2 != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      co = 2;
    }
  }
  cout << co << endl;

  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

int gcd(int x, int y) {
  int r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}

int main() {
  int n, a[10001], t;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  t = a[0];
  for (int i = 1; i < n; i++) {
    t = gcd(t, a[i]);
  }
  std::cout << t << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

int gcd(int x, int y) {
  int r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}

int main() {
  int n, a[100001], t;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  t = a[0];
  for (int i = 1; i < n; i++) {
    t = gcd(t, a[i]);
  }
  std::cout << t << std::endl;
  return 0;
}
Problem p03127 (Python)

Buggy submission (status: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)


Fixed submission:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)
Problem p03127 (C++)

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

#define MAX_N 100000

int gcd(int n, int m) {
  if (n % m) {
    return gcd(m, n % m);
  } else {
    return m;
  }
}

int main() {
  int N;
  int A[MAX_N] = {0};
  int min = 1e9 + 100;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (A[i] >= A[j]) {
        if (A[j] % A[i]) {
          min = std::min(min, A[i] % A[j]);
          A[i] %= A[j];
        } else {
          min = std::min(min, A[j]);
          A[i] = A[j];
        }
      } else {
        if (A[j] % A[i]) {
          min = std::min(min, A[j] % A[i]);
          A[j] %= A[i];
        } else {
          min = std::min(min, A[i]);
          A[j] = A[i];
        }
      }
    }
  }
  cout << min << endl;
}


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

#define MAX_N 100000

int gcd(int n, int m) {
  if (n % m) {
    return gcd(m, n % m);
  } else {
    return m;
  }
}

int main() {
  int N;
  int A[MAX_N] = {0};
  int min = 1e9 + 100;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  for (int i = 1; i < N; i++) {
    min = std::min(min, gcd(A[i], A[0]));
  }
  cout << min << endl;
}
Problem p03127 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int gcd(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  return a % b == 0 ? b : gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int ans = gcd(a[0], a[1]);
  for (int i = 2; i < n;) {
    ans = gcd(ans, a[i]);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int gcd(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  return a % b == 0 ? b : gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int ans = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    ans = gcd(ans, a[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p03127 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

int main(void) {
  ll n;
  cin >> n;
  ll mini;
  bool bf = true;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  while (bf) {
    bf = false;
    for (int i = 1; i < n; i++) {
      if (a[i] % a[0] != 0) {
        ll temp = a[i] % a[0];
        bf = true;
        a.erase(a.begin() + i);
        a.insert(a.begin(), a[i] % a[0]);
      }
    }
  }
  cout << a[0] << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

int main(void) {
  ll n;
  cin >> n;
  ll mini;
  bool bf = true;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  while (bf) {
    bf = false;
    for (int i = 1; i < n; i++) {
      if (a[i] % a[0] != 0) {
        ll temp = a[i] % a[0];
        bf = true;
        a.erase(a.begin() + i);
        a.insert(a.begin(), temp);
      }
    }
  }
  cout << a[0] << endl;
  return 0;
}
Problem p03127 (C++)

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

using namespace std;

long long A[10101];

int main() {
  int N;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  int id;
  while (A[N - 2] != 0) {
    for (int i = 0; i < N; i++) {
      if (A[i] > 0) {
        id = i;
        break;
      }
    }
    if (id == N - 1)
      break;
    for (int i = id + 1; i < N; i++) {
      A[i] %= A[id];
    }
    sort(A, A + N);
  }
  cout << A[N - 1] << endl;
}

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

using namespace std;

long long A[101010];

int main() {
  int N;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  int id;
  while (A[N - 2] != 0) {
    for (int i = 0; i < N; i++) {
      if (A[i] > 0) {
        id = i;
        break;
      }
    }
    if (id == N - 1)
      break;
    for (int i = id + 1; i < N; i++) {
      A[i] %= A[id];
    }
    sort(A, A + N);
  }
  cout << A[N - 1] << endl;
}
Problem p03127 (C++)

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

int gcd(int a, int b) {
  if (a > b) {
    return gcd(b, a);
  } else {
    if (b % a == 0) {
      return a;
    } else {
      return gcd(b % a, a);
    }
  }
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++)
    std::cin >> a[i];
  int ans = a[0];
  for (auto x : a) {
    bool flag = true;
    for (auto y : a) {
      int r = gcd(x, y);
      if (r == 1) {
        std::cout << r << std::endl;
        return 0;
      }
      ans = std::min(r, ans);
      if (flag && r == x || r == y)
        flag = false;
    }
    if (flag)
      break;
  }
  std::cout << ans << std::endl;
}


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

int gcd(int a, int b) {
  if (a > b) {
    return gcd(b, a);
  } else {
    if (b % a == 0) {
      return a;
    } else {
      return gcd(b % a, a);
    }
  }
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++)
    std::cin >> a[i];
  int ans = a[0];
  for (int i = 1; i < n; i++) {
    ans = gcd(ans, a[i]);
  }
  std::cout << ans << std::endl;
}
Problem p03127 (C++)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    a[i + 1] = gcd(a[i], a[i + 1]);
  }
  cout << a[n - 1] << endl;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  for (int i = 0; i < n - 1; i++) {
    a[i + 1] = gcd(a[i], a[i + 1]);
  }
  cout << a[n - 1] << endl;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 35;
int n, ans, a[M];

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a[1];
  ans = a[1];
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    ans = __gcd(ans, a[i]);
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 1e5 + 5;
int n, ans, a[M];

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a[1];
  ans = a[1];
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    ans = __gcd(ans, a[i]);
  }
  cout << ans;
  return 0;
}
Problem p03127 (C++)

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

int gcd(int a, int b) {
  if (b >= a)
    return gcd(b, a);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int n, ret;
  cin >> n >> ret;
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    ret = gcd(ret, a);
  }
  cout << ret;
  return 0;
}

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

int gcd(int a, int b) {
  if (b > a)
    return gcd(b, a);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int n, ret;
  cin >> n >> ret;
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    ret = gcd(ret, a);
  }
  cout << ret;
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Time Limit Exceeded):


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int INF = (1 << 30);
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  //
  int N;
  cin >> N;

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

  int ans = INF;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ans = min(ans, gcd(A[i], A[j]));
    }
  }

  //
  cout << ans << endl;

  return 0;
}

Fixed submission:


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int INF = (1 << 30);
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  //
  int N;
  cin >> N;

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

  int ans = INF;
  for (int i = 1; i < N; ++i) {
    ans = min(ans, gcd(A[0], A[i]));
    //    for (int j = i+1; j < N; ++j) {
    //    }
  }

  //
  cout << ans << endl;

  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
long gcd(long a, long b) {
  if (a == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int n;
  cin >> n;
  long A[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> A[i];
  }

  long ans = A[0];
  for (i = 1; i < n; i++) {
    ans = gcd(ans, A[i]);
  }
  cout << ans;
}

Fixed submission:
#include <iostream>
using namespace std;
long gcd(long a, long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int n;
  cin >> n;
  long A[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> A[i];
  }

  long ans = A[0];
  for (i = 1; i < n; i++) {
    ans = gcd(ans, A[i]);
  }
  cout << ans;
}
Problem p03127 (C++)

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

int main() {
  vector<int> dtom{-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int n, m;
  cin >> n;
  long long int min = 10000000000;

  priority_queue<int> pq;
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    pq.push(temp);
  }
  while (pq.size() != 1) {
    int n1 = pq.top();
    pq.pop();
    int n2 = pq.top();
    pq.pop();
    n1 = n1 - n2;
    if (n1 != 0)
      pq.push(n1);
    pq.push(n2);
  }
  cout << pq.top();
  return 0;
}

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

int main() {
  vector<int> dtom{-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int n, m;
  cin >> n;
  long long int min = 10000000000;

  priority_queue<int> pq;
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    pq.push(temp);
  }
  while (pq.size() != 1) {
    int n1 = pq.top();
    pq.pop();
    int n2 = pq.top();
    pq.pop();
    n1 = n1 % n2;
    if (n1 != 0)
      pq.push(n1);
    pq.push(n2);
  }
  cout << pq.top();
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) {
  if (a < b) {
    ll temp = a;
    a = b;
    b = temp;
  }
  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return 0;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n - 1; i++) {
    ll g = gcd(a[i], a[i + 1]);
    a[i + 1] = g;
  }
  cout << a.back() << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
ll gcd(ll a, ll b) {
  if (a < b) {
    ll temp = a;
    a = b;
    b = temp;
  }
  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n - 1; i++) {
    ll g = gcd(a[i], a[i + 1]);
    a[i + 1] = g;
  }
  cout << a.back() << endl;
  return 0;
}
Problem p03127 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A) {
    cin >> a;
  }

  sort(A.begin(), A.end());
  int s = 0;
  while (s < N - 1) {
    if (A[s] == 1) {
      break;
    }
    for (int ii = s + 1; ii < N; ii++) {
      A[ii] -= A[s];
    }
    sort(A.begin(), A.end());
    while (A[s] == 0) {
      s++;
    }
  }
  cout << A[s] << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A) {
    cin >> a;
  }

  sort(A.begin(), A.end());
  int s = 0;
  while (s < N - 1) {
    if (A[s] == 1) {
      break;
    }
    for (int ii = s + 1; ii < N; ii++) {
      A[ii] %= A[s];
    }
    sort(A.begin(), A.end());
    while (A[s] == 0) {
      s++;
    }
  }
  cout << A[s] << endl;
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define ll long long
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<ll>::iterator min_it;
  int minIndex;
  ll min;
  while (a.size() > 1) {
    min_it = min_element(a.begin(), a.end());
    minIndex = distance(a.begin(), min_it);
    min = a[minIndex];
    for (int i = 0; i < a.size(); i++) {
      if (i != minIndex) {
        a[i] = a[i] % min;
      }
    }
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == 0) {
        a.erase(a.begin() + i);
      }
    }
  }
  cout << a[0];
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define ll long long
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<ll>::iterator min_it;
  int minIndex;
  ll min;
  while (a.size() > 1) {
    min_it = min_element(a.begin(), a.end());
    minIndex = distance(a.begin(), min_it);
    min = a[minIndex];
    for (int i = 0; i < a.size(); i++) {
      if (i != minIndex) {
        a[i] = a[i] % min;
      }
    }
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == 0) {
        a.erase(a.begin() + i);
        i--;
      }
    }
  }
  cout << a[0];
  return 0;
}
Problem p03127 (C++)

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

signed main() {
  int n, mi = 1000000000;
  bool bou = true;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  int a = 1;
  while (1) {
    a *= 2;
    for (int i = 0; i < vec.size(); i += a) {
      // cout<<vec[i]<<" "<<vec[i+a/2]<<endl;
      if (vec[i + a / 2] <= vec.size()) {
        vec[i] = __gcd(vec[i + a / 2], vec[i]);
      }
      // cout<<vec[i]<<endl;
    }
    if (a * 2 > vec.size())
      break;
  }
  cout << vec[0] << endl;
}

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

signed main() {
  int n, mi = 1000000000;
  bool bou = true;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  int a = 1;
  while (1) {
    a *= 2;
    for (int i = 0; i < vec.size(); i += a) {
      // cout<<vec[i]<<" "<<vec[i+a/2]<<endl;
      if (i + a / 2 <= vec.size()) {
        vec[i] = __gcd(vec[i + a / 2], vec[i]);
      }
      // cout<<vec[i]<<endl;
    }
    if (a * 2 > vec.size())
      break;
  }
  cout << vec[0] << endl;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(void) {
  int n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = a[0];
  rep(i, n) ans = __gcd(ans, a[i]);

  cout << ans << endl;
  return 0;
}


Fixed submission:
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = a[0];
  rep(i, n) ans = __gcd(ans, a[i]);

  cout << ans << endl;
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int GCD(int x, int y) { return x ? GCD(y % x, x) : y; }
int main() {
  int n;
  cin >> n;
  vector<int> k;
  for (int i = 0; i < n; i++)
    cin >> k.at(i);
  int s = k[0];
  for (int i = 0; i < n; i++)
    s = GCD(s, k.at(i));
  cout << s << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int GCD(int x, int y) { return x ? GCD(y % x, x) : y; }
int main() {
  int n;
  cin >> n;
  vector<int> k(n);
  for (int i = 0; i < n; i++)
    cin >> k.at(i);
  int s = k[0];
  for (int i = 0; i < n; i++)
    s = GCD(s, k.at(i));
  cout << s << endl;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int N_MAX = 2000;
long gcd(long m, long n) {
  while (m > 0 && n > 0) {
    n = n % m;
    if (n > 0)
      m = m % n;
  }
  if (n == 0)
    return m;
  else
    return n;
}
int main() {
  int n;
  cin >> n;
  int a[N_MAX];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long res = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++)
    res = gcd(res, a[i]);
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int N_MAX = 100000;
long gcd(long m, long n) {
  while (m > 0 && n > 0) {
    n = n % m;
    if (n > 0)
      m = m % n;
  }
  if (n == 0)
    return m;
  else
    return n;
}
int main() {
  int n;
  cin >> n;
  int a[N_MAX];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long res = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++)
    res = gcd(res, a[i]);
  cout << res << endl;
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(), x.end()
#define fi first
#define se second
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<ll>());
  rep(i, n - 1) { a[i + 1] %= a[i]; }
  cout << a[n - 1] << endl;
}

Fixed submission:
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(), x.end()
#define fi first
#define se second
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  ll ans;
  rep(i, n - 1) { a[i + 1] = __gcd(a[i], a[i + 1]); }
  cout << a[n - 1] << endl;
}
Problem p03127 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>

using namespace std;

int calc_min(int x, int y) { return x % y == 0 ? y : calc_min(y, x % y); }

int main(void) {
  int n;
  int mon[100000];
  int min = 1000000000;
  int fmin = 0;

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

  for (int a = 0; a < n; a++) {
    for (int b = a + 1; b < n; b++) {
      fmin = calc_min(max(mon[a], mon[b]), std::min(mon[a], mon[b]));
      if (fmin < min)
        min = fmin;
    }
    if (min == 1)
      break;
  }

  printf("%d", min);

  scanf("%d");
  return 0;
}


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

using namespace std;

int calc_min(int x, int y) { return x % y == 0 ? y : calc_min(y, x % y); }

int main(void) {
  int n;
  int mon[100000];
  int min = 1000000000;
  int fmin = 0;

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

  for (int a = 1; a < n; a++) {
    fmin = calc_min(max(mon[a], mon[a - 1]), std::min(mon[a], mon[a - 1]));
    if (fmin < min)
      min = fmin;

    if (min == 1)
      break;
  }

  printf("%d", min);

  scanf("%d");
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

pair<ll, ll> mininarray(vector<ll> a, int n) {
  ll mina = a.at(0);
  int ind = 0;
  rep(p, n) {
    if (a.at(p) != 0) {
      if (mina > a.at(p)) {
        mina = a.at(p);
        ind = p;
      }
    }
  }

  return make_pair(mina, ind);
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);

  pair<ll, ll> minind;
  ll mina, inda;

  bool flag = 1;
  while (flag) {
    flag = 0;
    minind = mininarray(a, n);
    mina = minind.first;
    inda = minind.second;
    rep(i, n) {
      if (i != inda) {
        a.at(i) = a.at(i) % mina;
        if (a.at(i) != 0)
          flag = 1;
      }
      // cout << a.at(i) << ' ';
    }
    // cout << endl;
  }

  cout << mina << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

pair<ll, ll> mininarray(vector<ll> a, int n) {
  ll mina = 1000000000;
  int ind = 0;
  rep(p, n) {
    if (a.at(p) != 0) {
      if (mina > a.at(p)) {
        mina = a.at(p);
        ind = p;
      }
    }
  }

  return make_pair(mina, ind);
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);

  pair<ll, ll> minind;
  ll mina, inda;

  bool flag = 1;
  while (flag) {
    flag = 0;
    minind = mininarray(a, n);
    mina = minind.first;
    inda = minind.second;
    rep(i, n) {
      if (i != inda) {
        a.at(i) = a.at(i) % mina;
        if (a.at(i) != 0)
          flag = 1;
      }
      // cout << a.at(i) << ' ';
    }
    // cout << endl;
  }

  cout << mina << endl;
}
Problem p03127 (C++)

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

// #define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAX = 1e5 + 1;

void solve() {
  int n;
  cin >> n;
  int a[MAX];
  int g = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    g = __gcd(g, a[i]);
  }

  cout << g << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime="
       << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000)
       << "ms\n\x1b[0m";
#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAX = 1e5 + 1;

void solve() {
  int n;
  cin >> n;
  int a[MAX];
  int g = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    g = __gcd(g, a[i]);
  }

  cout << g << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime="
       << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000)
       << "ms\n\x1b[0m";
#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////
Problem p03127 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

long long int gcd(long long int a, long long int b) {
  long long int tmp;
  while (1) {
    if (a % b == 0) {
      return b;
      break;
    } else {
      if (a > b)
        a = a - b;
      tmp = a;
      a = b;
      b = tmp;
    }
  }
}

int main(void) {
  long long int n, i, j, ans;
  scanf("%lld", &n);
  int a[n];
  for (i = 0; i < n; i++)
    scanf("%lld", &a[i]);

  ans = a[0];
  for (i = 0; i < n; i++)
    ans = gcd(ans, a[i]);
  printf("%lld", ans);
}

Fixed submission:
#include <stdio.h>

long long int gcd(long long int a, long long int b) {
  long long int tmp;
  while (1) {
    if (a % b == 0) {
      return b;
      break;
    } else {
      a = a % b;
      tmp = a;
      a = b;
      b = tmp;
    }
  }
}

int main(void) {
  long long int n, i, j, ans;
  scanf("%lld", &n);
  int a[n];
  for (i = 0; i < n; i++)
    scanf("%lld", &a[i]);

  ans = a[0];
  for (i = 0; i < n; i++)
    ans = gcd(ans, a[i]);
  printf("%lld", ans);
}
Problem p03127 (C++)

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

int n;

int a;

int gcd(int x, int y) {
  if (x > y)
    std::swap(x, y);
  return (x == 1) ? y : gcd(y % x, x);
}

int main() {

  std::cin >> n;

  std::cin >> a;

  int g = a;

  for (int i = 0; i < n - 1; ++i) {
    std::cin >> a;
    g = gcd(g, a);
  }

  std::cout << g << std::endl;

  return 0;
}

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

int n;

int a;

int gcd(int x, int y) {
  if (x > y)
    std::swap(x, y);
  return (x == 0) ? y : gcd(y % x, x);
}

int main() {

  std::cin >> n;

  std::cin >> a;

  int g = a;

  for (int i = 0; i < n - 1; ++i) {
    std::cin >> a;
    g = gcd(g, a);
  }

  std::cout << g << std::endl;

  return 0;
}
Problem p03127 (C++)

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

int GCD(int a, int b) {

  int c;
  c = a % b;
  a = b;
  b = c;

  if (c == 0) {
    return a;
  } else {
    return GCD(a, b);
  }
}

int main() {

  int N, i, j, mn = 1000000000;
  cin >> N;
  vector<int> A(N);
  for (i = 0; i < N; i++)
    cin >> A[i];
  for (i = 0; i < N; i++) {
    for (j = i + 1; j < N; j++) {
      mn = min(mn, GCD(A[i], A[j]));
    }
  }
  cout << mn << endl;
  return 0;
}

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

int GCD(int a, int b) {

  int c;
  c = a % b;
  a = b;
  b = c;

  if (c == 0) {
    return a;
  } else {
    return GCD(a, b);
  }
}

int main() {

  int N, i, j, mn = 1000000000;
  cin >> N;
  vector<int> A(N);
  for (i = 0; i < N; i++)
    cin >> A[i];
  for (i = 0; i < N - 1; i++) {
    mn = min(mn, GCD(A[i], A[i + 1]));
  }
  cout << mn << endl;
  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> P3;
const ll MOD = ll(1e9) + 7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int gcd(int p, int q) {
  if (p % q == 0)
    return q;
  else
    return gcd(q, p % q);
}

int main() {
  int n, ans = 0;
  cin >> n;
  REP(i, n) {
    int a;
    cin >> a;
    ans = gcd(a, ans);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> P3;
const ll MOD = ll(1e9) + 7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int gcd(int p, int q) {
  if (q == 0)
    return p;
  else
    return gcd(q, p % q);
}

int main() {
  int n, ans = 0;
  cin >> n;
  REP(i, n) {
    int a;
    cin >> a;
    ans = gcd(a, ans);
  }
  cout << ans << endl;
  return 0;
}
Problem p03127 (C++)

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

int gcd(int a, int b);
int gcd(std::vector<int> a);

int main() {
  int n;

  std::vector<int> v(n);
  for (int &x : v) {
    std::cin >> x;
  }

  std::cout << gcd(v) << std::endl;

  return 0;
}

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}

int gcd(std::vector<int> a) {
  int ans = a[0];
  for (int i = 0; i < a.size(); i++) {
    ans = gcd(ans, a[i]);
  }
  return ans;
}


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

int gcd(int a, int b);
int gcd(std::vector<int> a);

int main() {
  int n;

  std::cin >> n;

  std::vector<int> v(n);
  for (int &x : v) {
    std::cin >> x;
  }

  std::cout << gcd(v) << std::endl;

  return 0;
}

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}

int gcd(std::vector<int> a) {
  int ans = a[0];
  for (int i = 0; i < a.size(); i++) {
    ans = gcd(ans, a[i]);
  }
  return ans;
}
Problem p03127 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
  int N;
  cin >> N;

  vector<int> A(N);

  for (int i = 0; i < N; i++)
    cin >> A[i];

  int ans = A[0];

  for (int i = 0; i < N - 1; i++) {
    for (int j = i; j < N; j++) {
      ans = min(ans, gcd(A[i], A[j]));
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
  int N;
  cin >> N;

  vector<int> A(N);

  for (int i = 0; i < N; i++)
    cin >> A[i];

  int ans = A[0];

  for (int i = 0; i < N - 1; i++) {
    ans = min(ans, gcd(A[i], A[i + 1]));
  }

  cout << ans << endl;

  return 0;
}
Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
#define MAX 10000
int N;
long int A[MAX];

bool one_survive() {
  int survive = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > 0) {
      survive += 1;
    }
  }
  if (survive == 1) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    long int a;
    cin >> a;
    A[i] = a;
  }
  // long int minimum = A[0];
  long int min_val = A[0];
  int min_idx = 0;
  while (true) {
    if (one_survive()) {
      break;
    }
    for (int i = 0; i < N; i++) {
      if (A[i] > 0 && min_val >= A[i]) {
        min_val = A[i];
        min_idx = i;
      }
    }
    for (int i = 0; i < N; i++) {
      if (i == min_idx || A[i] <= 0) {
        continue;
      } else {
        A[i] %= min_val;
      }
    }
  }
  cout << min_val << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
#define MAX 100000
int N;
long int A[MAX];

bool one_survive() {
  int survive = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > 0) {
      survive += 1;
    }
  }
  if (survive == 1) {
    return true;
  } else {
    return false;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    long int a;
    cin >> a;
    A[i] = a;
  }
  // long int minimum = A[0];
  long int min_val = A[0];
  int min_idx = 0;
  while (true) {
    if (one_survive()) {
      break;
    }
    for (int i = 0; i < N; i++) {
      if (A[i] > 0 && min_val >= A[i]) {
        min_val = A[i];
        min_idx = i;
      }
    }
    for (int i = 0; i < N; i++) {
      if (i == min_idx || A[i] <= 0) {
        continue;
      } else {
        A[i] %= min_val;
      }
    }
  }
  cout << min_val << endl;
  return 0;
}