Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200005;
ll n, s[N], a[N], s1, s2, ans = 1e18;
ll find (ll l, ll r, ll x) {
	while (l < r) {
		ll mid = (l + r + 1) >> 1;
		if (s[mid] <= x)
			l = mid;
		else r = mid - 1;
	}
	return l;
}
ll Abs(ll x) {
	return max(x, -x);
}	
int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> s[i];
		s[i] += s[i - 1];
	}
	for (int i = 2; i < n - 1; i ++) {
		s1 = find(0, i, s[i]>>1);
		s2 = find(i + 1, n, s[i] + ((s[n] - s[i]) >> 1));
		ll x = 0, y = 0;
		if (Abs(s[i] - (s[s1] << 1)) < Abs(s[i] - (s[s1 + 1] << 1)))
			x = s1; 
		else
			x = s1 + 1;	
		if (Abs(s[n] - (s[s2] << 1) + s[i]) < Abs(s[n] - (s[s2 + 1] << 1) + s[i]))
			y = s2; 
		else 
			y = s2 + 1;
		ans = min(max(max(s[x], s[i] - s[x]), max(s[y] - s[i], s[n] - s[y])) - min(min(s[x], s[i] - s[x]), min(s[y] - s[i], s[n] - s[y])), ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const long long int>]':
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = long long int]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:12:   required from here
   25 |                 s1 = find(0, i, s[i]>>1);
      |                      ~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2153:48: error: no matching function for call to '__iterator_category(int&)'
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:65:
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note: candidate: 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&)'
  239 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_iterator_base_types.h: In substitution of 'template<class _Iter> constexpr typename std::iterator_traits< <template-parameter-1-1> >::iterator_category std::__iterator_category(const _Iter&) [with _Iter = int]':
/usr/include/c++/14/bits/stl_algobase.h:2153:34:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const long long int>]'
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = long long int]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:12:   required from here
   25 |                 s1 = find(0, i, s[i]>>1);
      |                      ~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:239:5: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'
  239 |     __iterator_category(const _Iter&)
      |     ^~~~~~~~~~~~~~~~~~~