#include "bits/stdc++.h"
using namespace std;
#define int long long
using ll = long long;


signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int N; cin >> N;
	vector<int>A(N);
	vector<int>sum(N + 1), ma(N+1);
	int before = 0;
	int tmp = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
		if (A[i] > 0) {
			ma[i + 1] = max(ma[i], tmp + A[i]);
		}
		else {
			ma[i + 1] = max(ma[i], tmp);
		}
		before += A[i];
		tmp = before;
	}
	vector<int>sum2(N + 1);
	int now = 0;
	for (int i = 1; i <= N; i++) {
		sum2[i] = now + ma[i];
		now += sum[i];
	}
	int ans = 0;
	for (int i = 0; i <= N; i++) {
		ans = max(ans, sum2[i]);
	}
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int n, a, ans;

int32_t main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a);
		ans = __gcd(ans, a);
	}
	printf("%d\n", ans);
}
