Language: C++

using namespace std;

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

int ch(int a, int b) {
	if (a < b)
		swap(a, b);
	return gcd(a, b);
}

int main() {
	int n;
	cin >> n;
	vector<int> da(n),fo(n),ba(n);
	for (int i = 0;i < n;i++)
		cin >> da[i];

	if (n == 2) {
		cout << max(da[0], da[1]) << endl;
		return 0;
	}
	int x = da[0];
	fo[0] = x;
	for (int i = 1;i < n;i++) {
		fo[i] = ch(fo[i-1], da[i]);
	}
	x = da[n - 1];
	ba[n - 1] = x;
	for (int i = n - 2;i > -1;i--) {
		ba[i] = ch(ba[i+1], da[i]);
	}
	int ans = max(ba[1],fo[n-2]);
	for (int i = 1;i < n - 1;i++)
		ans = max(ans, ch(fo[i - 1], ba[i + 1]));
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int ch(int, int)':
a.cc:16:17: error: 'swap' was not declared in this scope
   16 |                 swap(a, b);
      |                 ^~~~
a.cc: In function 'int main()':
a.cc:22:9: error: 'cin' was not declared in this scope
   22 |         cin >> n;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:23:9: error: 'vector' was not declared in this scope
   23 |         vector<int> da(n),fo(n),ba(n);
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:23:16: error: expected primary-expression before 'int'
   23 |         vector<int> da(n),fo(n),ba(n);
      |                ^~~
a.cc:25:24: error: 'da' was not declared in this scope
   25 |                 cin >> da[i];
      |                        ^~
a.cc:28:17: error: 'cout' was not declared in this scope
   28 |                 cout << max(da[0], da[1]) << endl;
      |                 ^~~~
a.cc:28:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:28:29: error: 'da' was not declared in this scope
   28 |                 cout << max(da[0], da[1]) << endl;
      |                             ^~
a.cc:28:25: error: 'max' was not declared in this scope
   28 |                 cout << max(da[0], da[1]) << endl;
      |                         ^~~
a.cc:28:46: error: 'endl' was not declared in this scope
   28 |                 cout << max(da[0], da[1]) << endl;
      |                                              ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;
a.cc:31:17: error: 'da' was not declared in this scope
   31 |         int x = da[0];
      |                 ^~
a.cc:32:9: error: 'fo' was not declared in this scope
   32 |         fo[0] = x;
      |         ^~
a.cc:37:9: error: 'ba' was not declared in this scope
   37 |         ba[n - 1] = x;
      |         ^~
a.cc:41:19: error: 'max' was not declared in this scope
   41 |         int ans = max(ba[1],fo[n-2]);
      |                   ^~~
a.cc:44:9: error: 'cout' was not declared in this scope
   44 |         cout << ans << endl;
      |         ^~~~
a.cc:44:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:24: error: 'endl' was not declared in this scope
   44 |         cout << ans << endl;
      |                        ^~~~
a.cc:44:24: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc: In function 'int gcd(int, int)':
a.cc:10:20: warning: control reaches end of non-void function [-Wreturn-type]
   10 |                 gcd(a, b);
      |                 ~~~^~~~~~