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

struct SegmentTree {
  ll n;  // 最下段の数
  vector<ll> nodes;
  ll zero_value;
  function<ll(ll, ll)> calc;

  SegmentTree(vector<ll> vs, ll _zero_value, function<ll(ll, ll)> _calc) {
    zero_value = _zero_value;
    calc = _calc;
    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] = calc(nodes[i * 2 + 1], nodes[i * 2 + 2]);
    }
  }

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

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

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

  ll 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 calc(vl, vr);
  }
};

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

  SegmentTree st(as, 0, 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:35:3: error: 'function' does not name a type; did you mean 'union'?
   35 |   function<ll(ll, ll)> calc;
      |   ^~~~~~~~
      |   union
a.cc:37:46: error: 'function' has not been declared
   37 |   SegmentTree(vector<ll> vs, ll _zero_value, function<ll(ll, ll)> _calc) {
      |                                              ^~~~~~~~
a.cc:37:54: error: expected ',' or '...' before '<' token
   37 |   SegmentTree(vector<ll> vs, ll _zero_value, function<ll(ll, ll)> _calc) {
      |                                                      ^
a.cc: In constructor 'SegmentTree::SegmentTree(std::vector<long long int, std::allocator<long long int> >, ll, int)':
a.cc:39:5: error: 'calc' was not declared in this scope; did you mean 'calloc'?
   39 |     calc = _calc;
      |     ^~~~
      |     calloc
a.cc:39:12: error: '_calc' was not declared in this scope
   39 |     calc = _calc;
      |            ^~~~~
a.cc: In member function 'void SegmentTree::update(ll, ll)':
a.cc:61:18: error: 'calc' was not declared in this scope; did you mean 'calloc'?
   61 |       nodes[i] = calc(nodes[2 * i + 1], nodes[2 * i + 2]);
      |                  ^~~~
      |                  calloc
a.cc: In member function 'll SegmentTree::queryInternal(ll, ll, ll, ll, ll)':
a.cc:83:12: error: 'calc' was not declared in this scope; did you mean 'calloc'?
   83 |     return calc(vl, vr);
      |            ^~~~
      |            calloc
a.cc: In function 'void solve()':
a.cc:93:25: error: invalid conversion from 'll (*)(ll, ll)' {aka 'long long int (*)(long long int, long long int)'} to 'int' [-fpermissive]
   93 |   SegmentTree st(as, 0, mygcd);
      |                         ^~~~~
      |                         |
      |                         ll (*)(ll, ll) {aka long long int (*)(long long int, long long int)}
a.cc:37:46: note:   initializing argument 3 of 'SegmentTree::SegmentTree(std::vector<long long int, std::allocator<long long int> >, ll, int)'
   37 |   SegmentTree(vector<ll> vs, ll _zero_value, function<ll(ll, ll)> _calc) {
      |                                              ^~~~~~~~