Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int N; cin >> N;
    vector<ll> A(N), sum(N);
    ll ans = INF;
    sum[0] = 0;
    rep(i, N) {
        cin >> A[i];
        sum[i + 1] = sum[i] + A[i];
    }
    for(int i = 2, i <= N - 2; i++) {
        int j = lower_bound(sum.begin(), sum.end(), sum[i] / 2) - sum.begin();
        int k = lower_bound(sum.begin(), sum.end(), sum[i] + (sum[N] - sum[i] / 2)) - sum.begin();
        ll P1 = sum[j], Q1 = sum[i] - sum[j];
        ll P2 = sum[j + 1], Q1 = sum[i] - sum[j + 1];
        ll R1 = sum[k] - sum[i], S1 = sum[N] - sum[k];
        ll R2 = sum[k + 1] - sum[i], S2 = sum[N] - sum[k + 1];
        ll P, Q, R, S;
        if(abs(P1 - Q1) < abs(P2 - Q2) || j + 1 >= i) {
            P = P1; Q = Q1;
        } else {
            P = P2; Q = Q2;
        }
        if(abs(R1 - S1) < abs(R2 - S2) || k + 1 >= N) {
            R = R1; S = S1;
        } else {
            R = R2; S = S2;
        }
        ll ret = min({abs(P - Q), abs(P - R), abs(P - S), abs(Q - R), abs(Q - S), abs(R - S)});
        ans = min(ans, ret);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:58:21: error: expected ';' before '<=' token
   58 |     for(int i = 2, i <= N - 2; i++) {
      |                     ^~~
      |                     ;
a.cc:58:22: error: expected primary-expression before '<=' token
   58 |     for(int i = 2, i <= N - 2; i++) {
      |                      ^~
a.cc:62:29: error: redeclaration of 'll Q1'
   62 |         ll P2 = sum[j + 1], Q1 = sum[i] - sum[j + 1];
      |                             ^~
a.cc:61:25: note: 'll Q1' previously declared here
   61 |         ll P1 = sum[j], Q1 = sum[i] - sum[j];
      |                         ^~
a.cc:66:36: error: 'Q2' was not declared in this scope; did you mean 'Q'?
   66 |         if(abs(P1 - Q1) < abs(P2 - Q2) || j + 1 >= i) {
      |                                    ^~
      |                                    Q