#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N;
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> vec = A; 
  vector<int> MAX = A;

  REP(i, N-1) vec[i+1] += vec[i];

  int now = 0;
  int p = 0;
  REP(i, N-1){
    now += A[i];
    chmax(p, now);
    MAX[i+1] = p;
  }


  int ans = 0;
  now = 0;
  REP(i, N){
    chmax(ans, now+MAX[i]);

    now += vec[i];

    chmax(ans, now);
  }

  cout << ans << "\n";

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fs first
#define sc second
#define ll long long
 
// svarið er bara hversu mörg mismunandi gcd getum við búið til sem eru minni en 
// eða jöfn minnstu tölunni í upprunalega listanum.
 
// generally hversu mörg mismunandi gcd er hægt að búa til?
// loop down from min to 2 and find if there are two numbers who are both multiples of this number
// then it is a valid gcd
// gcd(a, b) <= min(a, b)
// ef ég fer út fyrir sqrt(10^9) þá get ég bara returnað stærðinni af listanum
// fyrst að ég veit að það er það eina sem er eftir og það er aðeins eitt eintak af því
// max í einhverri af tölunum. Eða ég tölunum eins oft og ég get með prime factornum 
// og þá get ég checkað hversu mörg duplicates
vector<int> primes;
void sieve(int n) {
	vector<bool> vis(n + 1, false);
	for(int i = 2; i <= n; i++) {
		for(int j = i + i; j <= n; j += i) {
			vis[j] = true;
		}
	}
	for(int i = 2; i <= n; i++) {
		if(!vis[i]) {
			primes.pb(i);
		}
	}
	
}
 
int n;
vector<int> A;
 
void getDivisors(int at, int cur, vector<pair<int, int>>& divs, vector<int>& res) {
	if(at == divs.size()) return;
	int a = cur;
	for(int i = 0; i <= divs[at].sc; i++) {
		if(a != 1) res.pb(a);
		getDivisors(at + 1, a, divs, res);
		a *= divs[at].fs;
	}
}

vector<ll> find_divisors(ll n){ // finds unique divisors, a divisor occurs only once in the result
	vector<pair<int,int>> pf;
	for(int p : primes) {
		if(p > n || n == 1) {
			break;
		}
		if(n % p == 0) {
			int cnt = 0;
			while(n % p == 0) {
				cnt++;
				n /= p;
			}
			pf.pb({p, cnt});
		}
	}
	if(n != 1) {
		pf.pb({n, 1});
	}
	vector<int> res = {1};
	getDivisors(0, 1, pf, res);
	return res;
}
 
signed main() {
	cin.sync_with_stdio(false);
	cin >> n;
	A = vector<int>(n);
	for(int i = 0; i < n; i++) {
		cin >> A[i];
	}
	
	sieve(sqrt(1e9) + 10);
	
	int mn = *min_element(A.begin(), A.end());
	
	unordered_map<int, int> t;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j * j <= A[i] && j < mn; j++) {
			if(A[i] % j == 0) {
				if(!t.count(j)) {
					t[j] = A[i];
				}else {
					t[j] = __gcd(t[j], A[i]);
				}
				if(A[i] / j < mn) {
					if(!t.count(A[i] / j)) {
						t[A[i] / j] = A[i];
					}else {
						t[A[i] / j] = __gcd(t[A[i] / j], A[i]);
					}
				}
			}
		}
	}
	
	int ans = 1;
	for(auto [a, b] : t) {
		if(a == b) ans++;
	}
	cout << ans << endl;
	
	
}