#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define int long long
using namespace std;
int sumarr[300005];
int input[300005];
int FindMinIndex(int start, int theend){
int themin = input[start];
int out = start;
for (int i = start; i <= theend; i++) {
if (input[i] < themin){
themin = input[i];
out = i;
}
}
return out;
}
signed main()
{
int n;
cin >> n;
int i;
int min = 0;
// input
for (i = 0; i < n; i++){
scanf("%lld", &input[i]);
if (i==0) sumarr[i] = input[i];
if (i>0) sumarr[i] = sumarr[i-1] + input[i];
}
int themin = 0, themax = n-1;
int curr = FindMinIndex(themin, themax); // curr = mid
// select
while(themax != themin){
int left = sumarr[curr-1] - sumarr[themin] + input[themin];
int right = sumarr[themax] - sumarr[curr+1] + input[curr+1];
// cout << left << " " << right << endl;
if (left > right ){
themax = curr-1;
curr = FindMinIndex(themin, themax);
}
else{
themin = curr+1;
curr = FindMinIndex(themin, themax);
}
}
// output
printf("%lld", input[themax]);
}