Language: C++

// https://atcoder.jp/contests/abc125/tasks/abc125_c

#include "algorithm"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

ll mygcd(ll a, ll b) { return b ? mygcd(b, a % b) : a; }

template <typename Monoid>
struct SegmentTree {
  ll n;  // 最下段の数
  vector<Monoid> nodes;
  ll zero_value;
  using F = function<Monoid(Monoid, Monoid)>;
  const F f;

  SegmentTree(vector<Monoid> vs, Monoid zero_value, F f)
      : zero_value(zero_value), f(f) {
    n = 1;

    while (n < vs.size()) {
      n *= 2;
    }

    nodes = vector<ll>(2 * n - 1, zero_value);

    rep(i, vs.size()) nodes[i + n - 1] = vs[i];

    for (ll i = n - 2; i >= 0; i--) {
      nodes[i] = f(nodes[i * 2 + 1], nodes[i * 2 + 2]);
    }
  }

  void update(Monoid i, Monoid val) {
    i += n - 1;
    nodes[i] = val;

    while (i > 0) {
      i = (i - 1) / 2;
      nodes[i] = f(nodes[2 * i + 1], nodes[2 * i + 2]);
    }
  }

  //  [from, to)
  Monoid query(ll from, ll to) {
    ll res = queryInternal(from, to, 0, 0, n);
    return res;
  }

  Monoid queryInternal(ll from, ll to, ll k, ll l, ll r) {
    if (r <= from || to <= l) {
      return zero_value;
    }

    if (from <= l && r <= to) {
      return nodes[k];
    }

    ll vl = queryInternal(from, to, 2 * k + 1, l, (l + r) / 2);
    ll vr = queryInternal(from, to, 2 * k + 2, (l + r) / 2, r);

    return f(vl, vr);
  }
};

void solve() {
  ll N;
  cin >> N;
  VL as(N);
  rep(i, N) cin >> as[i];

  SegmentTree<ll> st(as, 0ll, mygcd);

  ll res = 0;

  rep(i, N) {
    ll l = st.query(0, i);
    ll r = st.query(i + 1, as.size());
    chmax(res, mygcd(l, r));
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Compiler output:
a.cc:36:13: error: 'function' does not name a type; did you mean 'union'?
   36 |   using F = function<Monoid(Monoid, Monoid)>;
      |             ^~~~~~~~
      |             union
a.cc:37:9: error: 'F' does not name a type
   37 |   const F f;
      |         ^
a.cc:39:53: error: 'F' has not been declared
   39 |   SegmentTree(vector<Monoid> vs, Monoid zero_value, F f)
      |                                                     ^
a.cc: In constructor 'SegmentTree<Monoid>::SegmentTree(std::vector<_Tp>, Monoid, int)':
a.cc:40:33: error: class 'SegmentTree<Monoid>' does not have any field named 'f'
   40 |       : zero_value(zero_value), f(f) {
      |                                 ^
a.cc: In member function 'Monoid SegmentTree<Monoid>::queryInternal(ll, ll, ll, ll, ll)':
a.cc:84:12: error: there are no arguments to 'f' that depend on a template parameter, so a declaration of 'f' must be available [-fpermissive]
   84 |     return f(vl, vr);
      |            ^
a.cc:84:12: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In function 'void solve()':
a.cc:94:31: error: invalid conversion from 'll (*)(ll, ll)' {aka 'long long int (*)(long long int, long long int)'} to 'int' [-fpermissive]
   94 |   SegmentTree<ll> st(as, 0ll, mygcd);
      |                               ^~~~~
      |                               |
      |                               ll (*)(ll, ll) {aka long long int (*)(long long int, long long int)}
a.cc:39:55: note:   initializing argument 3 of 'SegmentTree<Monoid>::SegmentTree(std::vector<_Tp>, Monoid, int) [with Monoid = long long int]'
   39 |   SegmentTree(vector<Monoid> vs, Monoid zero_value, F f)
      |                                                     ~~^
a.cc: In instantiation of 'SegmentTree<Monoid>::SegmentTree(std::vector<_Tp>, Monoid, int) [with Monoid = long long int]':
a.cc:94:36:   required from here
   94 |   SegmentTree<ll> st(as, 0ll, mygcd);
      |                                    ^
a.cc:52:19: error: 'f' cannot be used as a function
   52 |       nodes[i] = f(nodes[i * 2 + 1], nodes[i * 2 + 2]);
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'Monoid SegmentTree<Monoid>::queryInternal(ll, ll, ll, ll, ll) [with Monoid = long long int; ll = long long int]':
a.cc:68:14:   required from 'Monoid SegmentTree<Monoid>::query(ll, ll) [with Monoid = long long int; ll = long long int]'
   68 |     ll res = queryInternal(from, to, 0, 0, n);
      |              ^~~~~~~~~~~~~
a.cc:99:20:   required from here
   99 |     ll l = st.query(0, i);
      |            ~~~~~~~~^~~~~~
a.cc:84:13: error: 'f' was not declared in this scope
   84 |     return f(vl, vr);
      |            ~^~~~~~~~