Problem p03127 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define pii std::pair<int, int>
#define pli std::pair<ll, int>
#define pil std::pair<int, ll>
#define psi std::pair<string, int>
#define pll std::pair<ll, ll>
#define pci std::pair<char, int>
#define sll(x) scanf("%lld", &x)
#define prll(x) printf("%lld ", x)
#define pri(x) printf("%d ", x)
#define si(x) scanf("%d", &x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int, int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int, ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const ll INF = 10000000000000;
const ll mod = 1e9 + 7;
using namespace std;
void add(ll &a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
ll mul(ll a, ll b) { return (a * b) % mod; }
ull Pow(ull a, ull b) {
  if (b == 0)
    return 1;
  ull c = Pow(a, b / 2);
  if (b % 2)
    return (a * ((c * c) % mod)) % mod;
  return (c * c) % mod;
}

int main() {
  IOS;
  cout.precision(30);
  int n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++)
    cin >> n;
  sort(a.begin(), a.end());
  ll gcd = 0;
  for (int i = 0; i < n; i++)
    gcd = __gcd(a[i], gcd);
  cout << gcd << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define pii std::pair<int, int>
#define pli std::pair<ll, int>
#define pil std::pair<int, ll>
#define psi std::pair<string, int>
#define pll std::pair<ll, ll>
#define pci std::pair<char, int>
#define sll(x) scanf("%lld", &x)
#define prll(x) printf("%lld ", x)
#define pri(x) printf("%d ", x)
#define si(x) scanf("%d", &x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int, int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int, ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const ll INF = 10000000000000;
const ll mod = 1e9 + 7;
using namespace std;
void add(ll &a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
ll mul(ll a, ll b) { return (a * b) % mod; }
ull Pow(ull a, ull b) {
  if (b == 0)
    return 1;
  ull c = Pow(a, b / 2);
  if (b % 2)
    return (a * ((c * c) % mod)) % mod;
  return (c * c) % mod;
}

int main() {
  IOS;
  cout.precision(30);
  int n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  ll gcd = 0;
  for (int i = 0; i < n; i++)
    gcd = __gcd(a[i], gcd);
  cout << gcd << endl;
  return 0;
}