Problem:
バームクーヘン(Baumkuchen)
JOI 君は妹のJOI 子ちゃんとJOI 美ちゃんと一緒におやつを食べようとしている．今日のおやつは3 人の大好物のバームクーヘンだ．
バームクーヘンは下図のような円筒形のお菓子である．3 人に分けるために，JOI 君は半径方向に刃を3回入れて，これを3 つのピースに切り分けなければならない．ただしこのバームクーヘンは本物の木材のように固いので，刃を入れるのは簡単ではない．そのためこのバームクーヘンにはあらかじめ $N$ 個の切れ込みが入っており，JOI 君は切れ込みのある位置でのみ切ることができる．切れ込みに1 から $N$ まで時計回りに番号をふったとき，$1 \leq i \leq N - 1$ に対し， $i$ 番目の切れ込みと$i + 1$ 番目の切れ込みの間の部分の大きさは $A_i$ である．また $N$ 番目の切れ込みと1 番目の切れ込みの間の部分の大きさは $A_N$ である．
図1: バームクーヘンの例 $N = 6, A_1 = 1, A_2 = 5, A_3 = 4, A_4 = 5, A_5 = 2, A_6 = 4$
課題
切れ込みの個数 $N$ と，各部分の大きさを表す整数 $A_1,...,A_N$ が与えられる．バームクーヘンを3 つに切り分けたときの，最も小さいピースの大きさの最大値を出力するプログラムを作成せよ．
入力
標準入力から以下のデータを読み込め．
1 行目には，整数 $N$ が書かれている．これはバームクーヘンに $N$ 個の切れ込みがあることを表す．
続く$N$ 行のうちの $i$ 行目$(1 \leq i \leq N)$ には，整数 $A_i$ が書かれている．これは $i$ 番目の切れ込みと $i + 1$ 番目の切れ込みの間の部分 ($i = N$ のときは $N$ 番目の切れ込みと1 番目の切れ込みの間の部分) の大きさが $A_i$ であることを表す．
出力
標準出力に，バームクーヘンを3 つに切り分けたときの，最も小さいピースの大きさの最大値を表す整数を1 行で出力せよ．
制限
すべての入力データは以下の条件を満たす．
$3 \leq N \leq 100000$
$1 \leq A_i \leq 1000000000 (1 \leq i \leq N)$
入出力例
入力例 1
6
1
5
4
5
2
4
出力例 1
6
図2: 1 番目の切れ込みと3 番目の切れ込みと5 番目の切れ込みで切るのが最善である．
入力例 2
30
1
34
44
13
30
1
9
3
7
7
20
12
2
44
6
9
44
31
17
20
33
18
48
23
19
31
24
50
43
15
出力例 2
213
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, a[200009]; long long sum[200009];
bool solve(long long x) {
	for (int i = 0; i < n; i++) {
		int ptr1 = lower_bound(sum + i, sum + n + i, x + sum[i]) - sum;
		if (ptr1 == n + i) continue;
		int ptr2 = lower_bound(sum + i, sum + n + i, x + sum[ptr1]) - sum;
		if (ptr2 == n + i) continue;
		if (sum[n + i] - sum[ptr2] >= x) return true;
	}
	return false;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]), a[n + i] = a[i];
	for (int i = 0; i < 2 * n; i++) sum[i + 1] = sum[i] + a[i];
	long long l = 0, r = 1LL << 60;
	while (r - l > 1) {
		long long m = (l + r) >> 1;
		if (solve(m)) l = m;
		else r = m;
	}
	printf("%lld\n", l);
	return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 5304
final_rank: 7

code_snippet: #include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <stack>
#include <complex>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(A) A.begin(), A.end()
#define itr(A, l, r) A.begin() + l, A.begin() + r
#define debug(var) cout << #var << " = " << var << endl;
typedef long long ll;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p)
{
    is >> p.first >> p.second;
    return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
    {
        os << v[i] << (i + 1 != (int)v.size() ? " " : "");
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
    {
        os << v[i] << endl;
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<vector<T>>> &v)
{
    int n = v.size();
    int m = v[0].size();
    int p = v[0][0].size();
    rep(k, p)
    {
        os << "k = " << k << endl;
        rep(i, n)
        {
            rep(j, m)
            {
                os << v[i][j][k];
                if (j < m - 1)
                {
                    os << " ";
                }
                else
                {
                    os << endl;
                }
            }
        }
    }
    return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &in : v)
        is >> in;
    return is;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, map<T, S> &mp)
{
    for (auto &[key, val] : mp)
    {
        os << key << ":" << val << " ";
    }
    cout << endl;
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, set<T> st)
{
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++)
    {
        os << *itr << (i + 1 != (int)st.size() ? " " : "");
        itr++;
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, multiset<T> st)
{
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++)
    {
        os << *itr << (i + 1 != (int)st.size() ? " " : "");
        itr++;
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, queue<T> q)
{
    while (q.size())
    {
        os << q.front() << " ";
        q.pop();
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, deque<T> q)
{
    while (q.size())
    {
        os << q.front() << " ";
        q.pop_front();
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, stack<T> st)
{
    while (st.size())
    {
        os << st.top() << " ";
        st.pop();
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, priority_queue<T> pq)
{
    while (pq.size())
    {
        os << pq.top() << " ";
        pq.pop();
    }
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, priority_queue<T, vector<T>, greater<T>> mpq)
{
    while (mpq.size())
    {
        os << mpq.top() << " ";
        mpq.pop();
    }
    return os;
}

int main(){
    #define int ll
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    // debug(a);
    vector<int> imos(2*n+1);
    rep(i,2*n){
        imos[i+1] = imos[i]+a[i%n];
    }
    // debug(imos);
    int ok = 0;
    int ng = 1e18;
    while(abs(ng-ok)>1){
        int mid = ng+ok;
        mid /= 2;
        // debug(mid);
        int R = 0;
        vector<int> idx(2*n,-1);
        rep(L,2*n){
            while(R<2*n && imos[R]-imos[L]<mid){
                R++;
            }
            idx[L] = R;
        }
        // debug(idx);
        idx.push_back(2*n);
        bool okay = false;
        rep(L,n){
            int nxt = idx[L];
            nxt = idx[nxt];
            nxt = idx[nxt];
            // debug(nxt);
            if(nxt-L<=n){
                okay = true;
            }
        }
        if(okay){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 10028
final_rank: 18

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
2-pointers ?
tricky as array is circular
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
//const int INF = 2147483647;
const int64_t INF = 1e18;

const int MAX_N = 100000;
static int64_t vect[MAX_N];

//------------------------------------------------------------------------------
void circular_shift(int N, int64_t A[], int K)
{
    rotate(A, A+N-K, A+N);
}

void shift(int N, int64_t A[])
{
    rotate(A, A+N-1, A+N);
}

//------------------------------------------------------------------------------
int64_t solve1(int N)
{
    //--------------------------------------------------------------------------
    // base cases:
    //--------------------------------------------------------------------------
    // init:
    int64_t L = vect[0];
    int64_t M = accumulate(vect+1, vect+N-1, 0L);
    int64_t R = vect[N-1];
    // for mid part:
    int start = 1;
    int back = N-2;
    //--------------------------------------------------------------------------
    // compute:
    int64_t res = min(L, min(M, R));
    int64_t d = 0;
    int64_t y = INF;
    while (true)
    {
        if (start == back) break;

        d = vect[start];
        y = min(L+d, min(M-d, R));
        if (y > res)
        {
            L += d;
            M -= d;
            res = y;
            start++;
            continue;
        }

        d = vect[back];
        y = min(L, min(M-d, R+d));
        if (y > res)
        {
            R += d;
            M -= d;
            res = y;
            back--;
            continue;
        }

        break;
    }
    //--------------------------------------------------------------------------
    
    //--------------------------------------------------------------------------
    // report:
    return res;
}

//------------------------------------------------------------------------------
int64_t solve(int N)
{
    //--------------------------------------------------------------------------
    // base cases:
    if (N == 3) return min(vect[0], min(vect[1], vect[2]));
    //--------------------------------------------------------------------------
    // init:
    //--------------------------------------------------------------------------
    // compute:
    int64_t res = 0;
    for (int i=0; i<N; ++i)
    {
        shift(N, vect);
        res = max(res, solve1(N));
    }
    //--------------------------------------------------------------------------
    // report:
    return res;
}


//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    num = scanf("%d ", &N);
    for (int i=0; i<N; ++i) num = scanf("%ld ", &vect[i]);
    int64_t res = solve(N);
    printf("%ld\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 0.52
time_ms: 150
memory_kb: 3632
final_rank: 20

code_snippet: #include <stdio.h>

#define NMAX 100000
#define D(x, y) (pos[(x)] - pos[(y)]) // 位置差分を計算するマクロ

long long A[NMAX];
long long pos[NMAX * 2];
int N;
long long L = 0; // 総和の初期化

// 最大値を計算する関数
long long solve() {
    long long max = 1;
    int p0 = 0, p1 = 1, p2 = 2;

    while (p0 < N) {
        // p1を調整して条件を満たす位置を見つける
        while (p1 - p0 < N - 1 && D(p1, p0) <= max) p1++;
        if (D(p1, p0) <= max) goto L1;

        // p2を調整して条件を満たす位置を見つける
        while (p2 - p0 < N && D(p2, p1) < D(p1, p0)) p2++;
        if (D(p2, p1) < D(p1, p0)) goto L1;

        // 条件を満たすか確認して最大値を更新
        if (L - D(p2, p0) >= D(p1, p0)) {
            max = D(p1, p0);
            if (max >= L / 3) return max; // 最大値が条件を満たした場合終了
            continue;
        }
    L1:
        p0 += 1;
        while (D(p2, p1) > D(p1, p0)) p2--;
    }
    return max;
}

int main(void) {
    int i;

    // 入力処理
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        L += A[i]; // 総和を計算
    }

    // 位置配列の初期化
    for (i = 1; i < 2 * N; i++) {
        pos[i] = pos[i - 1] + A[(i - 1) % N];
    }

    // 最大値の出力
    printf("%lld\n", solve());

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5324
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
  int n;
  cin >> n;
  
  vector<ll> a(n*2+1),s(n*2+1);
  s[0]=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    s[i+1]=s[i]+a[i];
    a[i+n]=a[i];
  }
  for(int i=n;i<n*2;i++){
    s[i+1]=s[i]+a[i];
  }
  
  ll lw=0,hg=s[n];
  
  while(hg-lw>1){
    ll md=(lw+hg)/2;
    int flg=0;
    
    for(int i=0;i<n;i++){
      int p1=distance(s.begin(),lower_bound(s.begin()+i,s.begin()+n+i,s[i]+md));
      if(p1==n+i) continue;
      int p2=distance(s.begin(),lower_bound(s.begin()+p1,s.begin()+n+i,s[p1]+md));
      if(p2==n+i) continue;
      int p3=distance(s.begin(),lower_bound(s.begin()+p2,s.begin()+n+1+i,s[p2]+md));
      if(p3!=n+1+i){
        flg=1;
        break;
      }
    }
    if(flg) lw=md;
    else hg=md;
  }
  cout << lw << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 6284
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

vector<ll> s(200010);

int res(int l,int r,int &b,int &e){
  //cout << l << " " << r << endl;
  if(r-l<=1){
    if(abs(s[e]+s[b]-2*s[l])>abs(s[e]+s[b]-2*s[r])) return r;
    return l;
  }
  int m=(r+l)/2;
  //cout << m << " " << s[e]-s[m] << " " << s[m]-s[b] << endl;
  if(s[e]-s[m]<s[m]-s[b]) return res(l,m,b,e);
  else return res(m,r,b,e);
}

int main() {
  int n;
  cin >> n;
  
  vector<ll> a(n*2+1);
  s[0]=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    s[i+1]=s[i]+a[i];
    a[i+n]=a[i];
  }
  for(int i=n;i<n*2;i++){
    s[i+1]=s[i]+a[i];
  }
  
  ll smx=0,cm,cmx;
  int bi,ci,e=n;
  for(int i=1;i<n;i++){
    int c=res(i,e,i,e);
    cm=min(s[i],min(s[e]-s[c],s[c]-s[i]));
    //cout << i << " " << cm << endl;
    if(cm>smx){
      smx=cm;
      bi=i;
      ci=c;
    }else if(cm<smx) break;
  }
  //cout << bi << " " << ci << " " << smx << endl;
  for(int i=1;i<n;i++){
    e=n+i;
    cmx=0;
    for(int j=bi;j<e;j++){
      int cj=max(ci,j);
      int c=res(cj,e,j,e);
      cm=min(s[j]-s[i],min(s[e]-s[c],s[c]-s[j]));
      //cout << i << " " << j << " " << c << " " <<cm << endl;
      if(cm>cmx){
        cmx=cm;
        bi=j;
        ci=c;
      }else if(cm<=cmx) break;
    }
    //cout << i << " " << cmx << endl;
    if(cmx>smx) smx=cmx;
  }
  cout << smx << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 6280
final_rank: 5

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    ll al = 0;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        al += a[i];
    }
    auto check = [&](ll x) -> bool {
        ll s1 = 0, s2 = 0;
        int l = 0;
        for (int i = 0; i < n; i++) {
            if (s1 < x) {
                s1 += a[i];
                l += 1;
            } else {
                break;
            }
        }
        if (s1 < x) return false;
        int r = l;
        for (int i = l; i < n; i++) {
            if (s2 < x) {
                s2 += a[i];
                r += 1;
            } else {
                break;
            }
        }
        if (s2 < x) return false;
        if (r == n) r = 0;
        for (int i = 0; i < n; i++) {
            while (s1 < x) {
                s1 += a[l];
                s2 -= a[l];
                l += 1;
                if (l == n) l = 0;
            }
            while (s2 < x) {
                s2 += a[r];
                r += 1;
                if (r == n) r = 0;
            }
            if (al - s1 - s2 >= x) return true;
            s1 -= a[i];
        }

        return false;
    };
    ll L = 0, R = 1e18;
    while (R - L > 1) {
        ll mid = (L + R) / 2;
        if (check(mid)) L = mid;
        else R = mid;
    }
    cout << L << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3900
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];
int64 dp[200000];

bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      sum, lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      sum, lower_bound(sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      sum, lower_bound(sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return (foo != N + pos + 1);
}

bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (dp[pos] >= size) // use the result of previous computation
      return true;
    if (Find(pos, size)) {
      dp[pos] = size;  // store the result of the computation
      return true;
    }
  }
  return false;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  memset(dp, 0, sizeof(dp));
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  printf("%lld\n", low);
}
accuracy: 1
time_ms: 210
memory_kb: 7116
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 prefixSum[400000];
bool result[200000];

bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      prefixSum, lower_bound(prefixSum + pos + 1, prefixSum + N + pos + 1, prefixSum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      prefixSum, lower_bound(prefixSum + hoge + 1, prefixSum + N + pos + 1, prefixSum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      prefixSum, lower_bound(prefixSum + fuga + 1, prefixSum + N + pos + 1, prefixSum[fuga] + size));
  return (foo != N + pos + 1);
}

bool calc(int64 size) {
  int windowSize = N - 1;
  int windowStart = 0;
  int windowEnd = windowSize;
  for (int i = 0; i < windowSize; i++) {
    result[i] = Find(i, size);
  }
  while (windowEnd < 2 * N) {
    result[windowEnd] = Find(windowEnd, size);
    if (result[windowStart]) {
      return true;
    }
    windowStart++;
    windowEnd++;
  }
  return false;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  prefixSum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    prefixSum[i] = prefixSum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  printf("%lld\n", low);
}
accuracy: 1
time_ms: 450
memory_kb: 5760
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
typedef long long int64;
const int64 INF = 1LL<<58;
int N;
std::vector<int64> sum(200000);

bool Find(const int &pos, const int64 &size) {
  int limit = N + pos + 1;
  int hoge = std::distance(sum.begin(), std::lower_bound(sum.begin() + pos + 1, sum.begin() + limit, sum[pos] + size));
  if (hoge == limit)
    return false;
  int fuga = std::distance(sum.begin(), std::lower_bound(sum.begin() + hoge + 1, sum.begin() + limit, sum[hoge] + size));
  if (fuga == limit)
    return false;
  int foo = std::distance(sum.begin(), std::lower_bound(sum.begin() + fuga + 1, sum.begin() + limit, sum[fuga] + size));
  return (foo != limit);
}

bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);

  std::cin>>N;
  std::vector<int> A(2*N);
  for (int i = 0; i < N; i++) {
    std::cin>>A[i];
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  std::cout<<low<<"\n";
}
accuracy: 1
time_ms: 210
memory_kb: 5212
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];

bool Find(const int &pos, const int64 &size) {
    int64 *ptr = lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size);
    if (ptr == sum + N + pos + 1)
        return false;
    int index1 = ptr - sum;

    ptr = lower_bound(sum + index1 + 1, sum + N + pos + 1, sum[index1] + size);
    if (ptr == sum + N + pos + 1)
        return false;
    int index2 = ptr - sum;

    ptr = lower_bound(sum + index2 + 1, sum + N + pos + 1, sum[index2] + size);
    return (ptr != sum + N + pos + 1);
}

bool calc(int64 size) {
    for (int pos = 0; pos < N; pos++) {
        if (Find(pos, size))
            return true;
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", A + i);
        A[N + i] = A[i];
    }
    sum[0] = A[0];
    for (int i = 1; i < 2 * N; i++) {
        sum[i] = sum[i - 1] + A[i];
    }
    int64 low = 0, high = INF;
    while (high != low) {
        int64 mid = (low + high + 1) >> 1;
        if (calc(mid))
            low = mid;
        else
            high = mid - 1;
    }
    printf("%lld\n", low);
}
accuracy: 1
time_ms: 230
memory_kb: 5588
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(2 * N);
  long long tot = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i + N] = A[i];
    tot += A[i];
  }
  long long tv = 0, fv = 1e18;
  while (fv - tv > 1) {
    long long mid = (tv + fv) / 2;
    int L = 0, R = 0;
    long long S = 0;
    vector<int> Lid(N, -1);
    vector<long long> Size(N, -1);
    while (L < N) {
      while (R < 2 * N && S < mid) {
        S += A[R];
        R++;
      }
      if (S >= mid) {
        Lid[L] = R;
        Size[L] = S;
      }
      if (L == R) {
        R++;
      } else {
        S -= A[L];
        L++;
      }
    }
    bool ok = false;
    for (int i = 0; i < N; i++) {
      int ni = Lid[i];
      if (ni == -1) continue;
      ni %= N;
      int nii = Lid[ni];
      if (nii == -1) continue;
      nii %= N;
      if (tot >= Size[i] + Size[ni] + Size[nii]) {
        ok = true;
      }
    }
    if (ok) {
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 5076
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(2 * N);
  long long tot = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i + N] = A[i];
    tot += A[i];
  }
  long long tv = 0, fv = 1e18;
  while (fv - tv > 1) {
    long long mid = (tv + fv) / 2;
    int L = 0, R = 0;
    long long S = 0;
    vector<int> Lid(N, -1);
    vector<long long> Size(N, -1);
    while (L < N) {
      while (R < 2 * N && S < mid) {
        S += A[R];
        R++;
      }
      if (S >= mid) {
        Lid[L] = R;
        Size[L] = S;
      }
      if (L == R) {
        R++;
      } else {
        S -= A[L];
        L++;
      }
    }
    bool ok = false;
    for (int i = 0; i < N; i++) {
      int ni = Lid[i];
      if (ni == -1) continue;
      ni %= N;
      int nii = Lid[ni];
      if (nii == -1) continue;
      nii %= N;
      if (tot - Size[i] - Size[ni] >= mid) {
        ok = true;
      }
    }
    if (ok) {
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 5076
final_rank: 3

code_snippet: #include <algorithm>
#include <cstdio>
#include <iterator>
#define MAX_NUM 200000
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[MAX_NUM * 2];
int64 sum[MAX_NUM * 2];

inline bool Find(const int pos, const int64 size) {
  int64 *end = sum + N + pos + 1;
  int64 *sum_pos = sum + pos;
  int64 *hoge = std::lower_bound(sum_pos + 1, end, *sum_pos + size);
  if (hoge == end) return false;
  int64 *fuga = std::lower_bound(hoge + 1, end, *hoge + size);
  if (fuga == end) return false;
  return std::lower_bound(fuga + 1, end, *fuga + size) != end;
}

inline bool calc(int64 size) {
  for (int pos = 0; pos < N; ++pos) {
    if (Find(pos, size)) return true;
  }
  return false;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; ++i) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid)) low = mid;
    else high = mid - 1;
  }
  printf("%lld\n", low);
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 5080
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];

int binary_search(int64 element, int start, int end){
    while(start <= end){
        int mid = start + (end - start) / 2;
        if(sum[mid] < element){
            start = mid + 1;
        }else{
            end = mid - 1;
        }
    }
    return start;
}
bool Find(const int &pos, const int64 &size) {
  int hoge = binary_search(sum[pos] + size, pos + 1, N + pos);
  if (hoge == N + pos + 1)
    return false;
  int fuga = binary_search(sum[hoge] + size, hoge + 1, N + pos);
  if (fuga == N + pos + 1)
    return false;
  int foo = binary_search(sum[fuga] + size, fuga + 1, N + pos);
  return (foo != N + pos + 1);
}
bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  printf("%lld\n", low);
}
accuracy: 1
time_ms: 250
memory_kb: 5548
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];
bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      sum, lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      sum, lower_bound(sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      sum, lower_bound(sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return (foo != N + pos + 1);
}
bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = sum[2 * N - 1] / 3;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  printf("%lld\n", low);
}
accuracy: 1
time_ms: 130
memory_kb: 5548
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];
bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      sum, lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      sum, lower_bound(sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      sum, lower_bound(sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return (foo != N + pos + 1);
}
bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  printf("%lld\n", low);
}
accuracy: 1
time_ms: 230
memory_kb: 5548
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
const int MAXN = 400000;
int N, A[MAXN];
int64 sum[MAXN];
bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      sum, lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      sum, lower_bound(sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      sum, lower_bound(sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return (foo != N + pos + 1);
}
bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  cout << low << "\n";
  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 5524
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];
bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      sum, lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      sum, lower_bound(sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      sum, lower_bound(sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return (foo != N + pos + 1);
}
bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  printf("%lld\n", low);
}
accuracy: 1
time_ms: 230
memory_kb: 5564
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;
int N, A[200000];
int64 sum[200000];
bool Find(const int &pos, const int64 &size) {
  int hoge = distance(
      sum, lower_bound(sum + pos + 1, sum + N + pos + 1, sum[pos] + size));
  if (hoge == N + pos + 1)
    return false;
  int fuga = distance(
      sum, lower_bound(sum + hoge + 1, sum + N + pos + 1, sum[hoge] + size));
  if (fuga == N + pos + 1)
    return false;
  int foo = distance(
      sum, lower_bound(sum + fuga + 1, sum + N + pos + 1, sum[fuga] + size));
  return (foo != N + pos + 1);
}
bool calc(int64 size) {
  for (int pos = 0; pos < N; pos++) {
    if (Find(pos, size))
      return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[N + i] = A[i];
  }
  sum[0] = A[0];
  for (int i = 1; i < 2 * N; i++) {
    sum[i] = sum[i - 1] + A[i];
  }
  int64 low = 0, high = INF;
  while (high != low) {
    int64 mid = (low + high + 1) >> 1;
    if (calc(mid))
      low = mid;
    else
      high = mid - 1;
  }
  cout << low << "\n";
  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 5500
final_rank: 11