Problem p03061 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum)                                                  \
  ;                                                                            \
  vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define debugP                                                                 \
  int debug_point;                                                             \
  cin >> debug_point;
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
  // cout << "The elements in the vector are: " << endl;
  for (auto x : V)
    cout << x << " ";
  cout << endl;
}
ll pown(ll fi, ll se) {
  ll ans = 1;
  rep(i, se) { ans *= fi; }
  return ans;
}
template <class T> vector<T> getv(ll n) {
  vector<T> Vector_temp;
  rep(i, n) {
    T input;
    cin >> input;
    Vector_temp.emplace_back(input);
  }
  return Vector_temp;
}
ll gcd(ll c, ll b) {
  while (1) {
    if (c % b != 0) {
      ll tmp = b;
      b = c % b;
      c = tmp;
    } else {
      return b;
    }
  }
}

/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main() {
  ll n;
  cin >> n;
  vec(v, n);
  rep(i, n) { cin >> v[i]; }
  vec(s, n);
  vec(g, n);
  s[0] = v[0];
  rep(i, n - 1) { s[i + 1] = gcd(v[i + 1], s[i]); }
  g[n - 1] = v[n - 1];
  rep(i, n - 1) { g[n - 1 - 1 - i] = gcd(v[n - 2 - i], g[n - 1 - i]); }
  ll ans = g[1];
  rep(i, n - 1) { ans = max(ans, gcd(s[i], g[2 + i])); }
  op(ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum)                                                  \
  ;                                                                            \
  vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define debugP                                                                 \
  int debug_point;                                                             \
  cin >> debug_point;
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
  // cout << "The elements in the vector are: " << endl;
  for (auto x : V)
    cout << x << " ";
  cout << endl;
}
ll pown(ll fi, ll se) {
  ll ans = 1;
  rep(i, se) { ans *= fi; }
  return ans;
}
template <class T> vector<T> getv(ll n) {
  vector<T> Vector_temp;
  rep(i, n) {
    T input;
    cin >> input;
    Vector_temp.emplace_back(input);
  }
  return Vector_temp;
}
ll gcd(ll c, ll b) {
  while (1) {
    if (c % b != 0) {
      ll tmp = b;
      b = c % b;
      c = tmp;
    } else {
      return b;
    }
  }
}

/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main() {
  ll n;
  cin >> n;
  vec(v, n);
  rep(i, n) { cin >> v[i]; }
  vec(s, n);
  vec(g, n);
  s[0] = v[0];
  rep(i, n - 1) { s[i + 1] = gcd(v[i + 1], s[i]); }
  g[n - 1] = v[n - 1];
  rep(i, n - 1) { g[n - 1 - 1 - i] = gcd(v[n - 2 - i], g[n - 1 - i]); }
  ll ans = g[1];
  rep(i, n - 2) { ans = max(ans, gcd(s[i], g[2 + i])); }
  ans = max(ans, s[n - 2]);
  op(ans);
  return 0;
}