#include<bits/stdc++.h>
using namespace std;
int n, a[1000005];
long long pre[1000005];
bool snt(int val) {
for (int i = 2; i * i <= val; i++)
if (val % i == 0) return false;
return true;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], pre[i]= pre[i - 1] + a[i];
long long Mn = 1e16, Ans = -1e16;
for (int r = 2; r <= n; r++)
if (snt(r)) {
/// r cung the la dong vao li
Mn = min(Mn, pre[r - 1]);
Ans = max(Ans, pre[r] - Mn);
}
cout << Ans;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgYVsxMDAwMDA1XTsKbG9uZyBsb25nIHByZVsxMDAwMDA1XTsKCmJvb2wgc250KGludCB2YWwpIHsKICAgIGZvciAoaW50IGkgPSAyOyBpICogaSA8PSB2YWw7IGkrKykKICAgICAgICBpZiAodmFsICUgaSA9PSAwKSByZXR1cm4gZmFsc2U7CiAgICByZXR1cm4gdHJ1ZTsKfQoKaW50IG1haW4oKSB7CiAgICBjaW4gPj4gbjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykKICAgICAgICBjaW4gPj4gYVtpXSwgcHJlW2ldPSBwcmVbaSAtIDFdICsgYVtpXTsKCiAgICBsb25nIGxvbmcgTW4gPSAxZTE2LCBBbnMgPSAtMWUxNjsKCiAgICBmb3IgKGludCByID0gMjsgciA8PSBuOyByKyspCiAgICAgICAgaWYgKHNudChyKSkgewogICAgICAgICAgICAvLy8gciBjdW5nIHRoZSBsYSBkb25nIHZhbyBsaQogICAgICAgICAgICBNbiA9IG1pbihNbiwgcHJlW3IgLSAxXSk7CiAgICAgICAgICAgIEFucyA9IG1heChBbnMsIHByZVtyXSAtIE1uKTsKICAgICAgICB9CgogICAgY291dCA8PCBBbnM7Cgp9Cg==