Language: C++

#include <bits/stdc++.h>
#define R register

typedef long long ll;

const int MN = 2e5 + 5;

inline int read(){
	R int x; R bool f; R char c;
	for (f = 0; (c = getchar()) < '0' || c > '9'; f = c == '-');
	for (x = c ^ '0'; (c = getchar()) >= '0' && c <= '9'; x = (x << 1) + (x << 3) + (c ^ '0'));
	return f ? -x : x;
}

int n;
ll sum[MN], ans;

inline int solve(int l, int r) {
	R int mid, ll, rr, pos;
	for (ll = l, rr = r; ll < rr; ) {
		mid = ll + rr >> 1;
		if (sum[mid] - sum[l - 1] < sum[r] - sum[mid]) ll = mid + 1;
		else rr = mid - 1;
	}
	R ll res = sum[n];
	for (R int i = std::max(l,ll - 2); i <= ll + 2 && i < r; ++i) {
		if (abs(sum[i] - sum[l - 1] - (sum[r] - sum[i])) < res){
			res = abs(sum[i] - sum[l - 1] - (sum[r] - sum[i])) ;
			pos = i;
		}
	}
	return pos;
}

int main() {
	n = read();
	for (R int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + read(); ans = sum[n];
	for (R int i = 2; i < n; ++i) {
		R int x, y;
		x = solve(1, i), y = solve(i + 1, n);
		R ll max, min;
		max = std::max(sum[x], sum[i] - sum[x]);
		max = std::max(max, std::max(sum[n] - sum[y], sum[y] - sum[i]));
		min = std::min(sum[x], sum[i] - sum[x]);
		min = std::min(min, std::min(sum[n] - sum[y], sum[y] - sum[i]));
		ans = std::min(ans, max - min);
	}
	printf("%lld\n", ans);
	return 0;
}

Compiler output:
a.cc: In function 'int read()':
a.cc:9:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 |         R int x; R bool f; R char c;
      |               ^
a.cc:9:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 |         R int x; R bool f; R char c;
      |                         ^
a.cc:9:35: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 |         R int x; R bool f; R char c;
      |                                   ^
a.cc: In function 'int solve(int, int)':
a.cc:19:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |         R int mid, ll, rr, pos;
      |               ^~~
a.cc:19:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |         R int mid, ll, rr, pos;
      |                    ^~
a.cc:19:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |         R int mid, ll, rr, pos;
      |                        ^~
a.cc:19:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 |         R int mid, ll, rr, pos;
      |                            ^~~
a.cc:25:11: error: 'll' does not name a type
   25 |         R ll res = sum[n];
      |           ^~
a.cc:26:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |         for (R int i = std::max(l,ll - 2); i <= ll + 2 && i < r; ++i) {
      |                    ^
a.cc:27:68: error: 'res' was not declared in this scope
   27 |                 if (abs(sum[i] - sum[l - 1] - (sum[r] - sum[i])) < res){
      |                                                                    ^~~
a.cc: In function 'int main()':
a.cc:37:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |         for (R int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + read(); ans = sum[n];
      |                    ^
a.cc:38:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   38 |         for (R int i = 2; i < n; ++i) {
      |                    ^
a.cc:39:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   39 |                 R int x, y;
      |                       ^
a.cc:39:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   39 |                 R int x, y;
      |                          ^
a.cc:41:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |                 R ll max, min;
      |                      ^~~
a.cc:41:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |                 R ll max, min;
      |                           ^~~