Language: C++

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define SIZE 200005

using namespace std;
typedef long long ll;

ll a[SIZE], n;

ll diff(ll m1, ll i, ll m2) {
	ll p, q, r, s;
	p = a[m1] - a[0];
	q = a[i] - a[m1];
	r = a[m2] - a[i];
	s = a[n] - a[m2];
	//cout << m1 << " " << i << " " << m2 << endl; 
	//cout << i << ": " << p << " " << q << " " << r << " " << s << endl;
	return (max(max(p, q), max(r, s)) - min(min(p, q), min(r, s)));
}

int main() {
	ll ans = INF, l, r, x, y, m1, m2, dx, dy;

	a[0] = 0;

	cin >> n;
	REP(i, n) cin >> a[i + 1];

	for (int i = 1; i <= n; i++) a[i] += a[i - 1];

	for (int i = 2; i <= n - 1; i++) {
		//debug(i);
		l = 1;
		r = i;
		m1 = l;
		while (l < r) {
			//debug(l);
			//debug(r);
			x = (r + 2 * l) / 3;
			y = (2 * r + l) / 3;
			if (x == l || y == r) break;
			dx = abs((a[x] - a[0]) - (a[i] - a[x]));
			dy = abs((a[y] - a[0]) - (a[i] - a[y]));
			//			if (d0>d) break;
			//			else d0 = d;
			if (dx >= dy) {
				l = x;
				m1 = y;
			} else {
				r = y;
				m1 = x;
			}
		}
		//debug(x);
		//debug(y);

		l = i + 1;
		r = n;
		m2 = l;
		while (l < r) {
			//debug(l);
			//debug(r);
			x = (r + 2 * l) / 3;
			y = (2 * r + l) / 3;
			dx = abs((a[x] - a[i]) - (a[n] - a[x]));
			dy = abs((a[y] - a[i]) - (a[n] - a[y]));
			//debug(dx);
			//debug(dy);
			if (x == l || y == r) break;
			
			if (dx >= dy) {
				l = x;
				m2 = y;
			} else {
				r = y;
				m2 = x;
			}
		}
		//debug(x);
		//debug(y);
		//debug(diff(m1, i, m2));
		ans = min(ans, diff(m1, i, m2));
		//debug(ans);
		//cerr << "--------------------" << endl;
	}
	cout << ans << endl;

	return 0;
}
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define SIZE 200005

using namespace std;
typedef long long ll;

ll a[SIZE], n;

ll diff(ll m1, ll i, ll m2) {
	ll p, q, r, s;
	p = a[m1] - a[0];
	q = a[i] - a[m1];
	r = a[m2] - a[i];
	s = a[n] - a[m2];
	//cout << m1 << " " << i << " " << m2 << endl; 
	//cout << i << ": " << p << " " << q << " " << r << " " << s << endl;
	return (max(max(p, q), max(r, s)) - min(min(p, q), min(r, s)));
}

int main() {
	ll ans = INF, l, r, x, y, m1, m2, dx, dy;

	a[0] = 0;

	cin >> n;
	REP(i, n) cin >> a[i + 1];

	for (int i = 1; i <= n; i++) a[i] += a[i - 1];

	for (int i = 2; i <= n - 1; i++) {
		//debug(i);
		l = 1;
		r = i;
		m1 = l;
		while (l < r) {
			//debug(l);
			//debug(r);
			x = (r + 2 * l) / 3;
			y = (2 * r + l) / 3;
			if (x == l || y == r) break;
			dx = abs((a[x] - a[0]) - (a[i] - a[x]));
			dy = abs((a[y] - a[0]) - (a[i] - a[y]));
			//			if (d0>d) break;
			//			else d0 = d;
			if (dx >= dy) {
				l = x;
				m1 = y;
			} else {
				r = y;
				m1 = x;
			}
		}
		//debug(x);
		//debug(y);

		l = i + 1;
		r = n;
		m2 = l;
		while (l < r) {
			//debug(l);
			//debug(r);
			x = (r + 2 * l) / 3;
			y = (2 * r + l) / 3;
			dx = abs((a[x] - a[i]) - (a[n] - a[x]));
			dy = abs((a[y] - a[i]) - (a[n] - a[y]));
			//debug(dx);
			//debug(dy);
			if (x == l || y == r) break;
			
			if (dx >= dy) {
				l = x;
				m2 = y;
			} else {
				r = y;
				m2 = x;
			}
		}
		//debug(x);
		//debug(y);
		//debug(diff(m1, i, m2));
		ans = min(ans, diff(m1, i, m2));
		//debug(ans);
		//cerr << "--------------------" << endl;
	}
	cout << ans << endl;

	return 0;
}


Compiler output:
a.cc:113:4: error: redefinition of 'll a [200005]'
  113 | ll a[SIZE], n;
      |    ^
a.cc:16:4: note: 'll a [200005]' previously declared here
   16 | ll a[SIZE], n;
      |    ^
a.cc:113:13: error: redefinition of 'll n'
  113 | ll a[SIZE], n;
      |             ^
a.cc:16:13: note: 'll n' previously declared here
   16 | ll a[SIZE], n;
      |             ^
a.cc:115:4: error: redefinition of 'll diff(ll, ll, ll)'
  115 | ll diff(ll m1, ll i, ll m2) {
      |    ^~~~
a.cc:18:4: note: 'll diff(ll, ll, ll)' previously defined here
   18 | ll diff(ll m1, ll i, ll m2) {
      |    ^~~~
a.cc:126:5: error: redefinition of 'int main()'
  126 | int main() {
      |     ^~~~
a.cc:29:5: note: 'int main()' previously defined here
   29 | int main() {
      |     ^~~~