//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define dd double
#define ld long double
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define el "\n"
#define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fix(x) cout << fixed << setprecision(x)
#define all(v) v.begin(),v.end()
void file()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
bool prime(int n) {
if (n == 2) return true;
if (n % 2 == 0 || n == 1) return false;
for (int i = 3; i * i <= n; i += 2)
if (n % i == 0) return false;
return true;
}
//Here We Go Again
int32_t main()
{
Arwa
int t=1;
//cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
map<int,int>m1,m2;
for(int i=0;i<n;i++)
cin>>arr[i];
int sum1=0,sum2=0,mx=LONG_LONG_MIN;
m1[0]=-1,m2[0]=n;
for(int i=0;i<n;i++)
{
sum1+=arr[i];
m1[sum1]=i;
}
for(int i=n-1;i>=0;i--)
{
sum2+=arr[i];
m2[sum2]=i;
}
for(auto it:m1)
{
if(m2[it.first]&&it.second<m2[it.first])
mx=max(mx,it.first);
}
cout<<max(mx,0)<<el;
}
return 0;
}
Ly8jaW5jbHVkZSA8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+IAovLyNpbmNsdWRlIDxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPiAKLy91c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsgCi8vI2RlZmluZSBvcmRlcmVkX3NldCB0cmVlPGludCwgbnVsbF90eXBlLGxlc3M8aW50PiwgcmJfdHJlZV90YWcsdHJlZV9vcm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ydWU7Cn0KLy9IZXJlIFdlIEdvIEFnYWluCmludDMyX3QgbWFpbigpIAp7CiAgICBBcndhCiAgICBpbnQgdD0xOwogICAgLy9jaW4+PnQ7CiAgICB3aGlsZSh0LS0pIAogICAgewogICAgICBpbnQgbjsKICAgICAgY2luPj5uOwogICAgICBpbnQgYXJyW25dOwogICAgICBtYXA8aW50LGludD5tMSxtMjsKICAgICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgY2luPj5hcnJbaV07CiAgICAgIGludCBzdW0xPTAsc3VtMj0wLG14PUxPTkdfTE9OR19NSU47CiAgICAgIG0xWzBdPS0xLG0yWzBdPW47CiAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspICAKICAgICAgeyAKICAgICAgc3VtMSs9YXJyW2ldOwogICAgICBtMVtzdW0xXT1pOwogICAgICB9CiAgICAgIGZvcihpbnQgaT1uLTE7aT49MDtpLS0pICAKICAgICAgeyAKICAgICAgc3VtMis9YXJyW2ldOwogICAgICBtMltzdW0yXT1pOwogICAgICB9CiAgICAgIGZvcihhdXRvIGl0Om0xKQogICAgICB7CiAgICAgICAgaWYobTJbaXQuZmlyc3RdJiZpdC5zZWNvbmQ8bTJbaXQuZmlyc3RdKQogICAgICAgIG14PW1heChteCxpdC5maXJzdCk7CiAgICAgIH0KICAgICAgY291dDw8bWF4KG14LDApPDxlbDsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==