Language: C++

#include <bits/stdc++.h>
 
#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
 
using namespace std;
 
typedef long long ll;
 
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }
 
namespace pb_ds {   
    namespace io {
        const int MaxBuff = 1 << 15;
        const int Output = 1 << 23;
        char B[MaxBuff], *S = B, *T = B;
        #define getc() ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) ? 0 : *S++)
        char Out[Output], *iter = Out;
        inline void flush() {
            fwrite(Out, 1, iter - Out, stdout);
            iter = Out;
        }
    }
 
    template<class Type = int> inline Type read() {
        using namespace io;
        register char ch; register Type ans = 0; register bool neg = 0;
        while(ch = getc(), (ch < '0' || ch > '9') && ch != '-')     ;
        ch == '-' ? neg = 1 : ans = ch - '0';
        while(ch = getc(), '0' <= ch && ch <= '9') ans = ans * 10 + ch - '0';
        return neg ? -ans : ans;
    }
}
 
using namespace pb_ds;
 
void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}
 
const int N = 3e5 + 1e3;
 
int n, a[N];
 
ll pre[N], suf[N];
 
priority_queue<int> Max;
priority_queue<int, vector<int>, greater<int>> Min;
 
int main () {
 
	File();
 
	n = read();
	For (i, 1, n * 3) a[i] = read();
 
	For (i, 1, n)
		Min.push(a[i]), pre[i] = pre[i - 1] + a[i];
 
	For (i, n + 1, 2 * n) {
		pre[i] = pre[i - 1];
		if (a[i] > Min.top())
			pre[i] += a[i] - Min.top(), Min.pop(), Min.push(a[i]);
	}
 
	Fordown (i, n * 3, n * 2 + 1)
		Max.push(a[i]), suf[i] = suf[i + 1] + a[i];
 
	Fordown (i, n * 2, n + 1) {
		suf[i] = suf[i + 1];
		if (a[i] < Max.top())
			suf[i] += a[i] - Max.top(), Max.pop(), Max.push(a[i]);
	}
 
	ll ans = pre[n] - suf[n + 1];
	For (i, n, 2 * n)
		chkmax(ans, pre[i] - suf[i + 1]);
	printf ("%lld\n", ans);
 
	return 0;
 

Compiler output:
a.cc: In function 'Type pb_ds::read()':
a.cc:32:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         register char ch; register Type ans = 0; register bool neg = 0;
      |                       ^~
a.cc:32:41: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         register char ch; register Type ans = 0; register bool neg = 0;
      |                                         ^~~
a.cc:32:64: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         register char ch; register Type ans = 0; register bool neg = 0;
      |                                                                ^~~
a.cc: In function 'int main()':
a.cc:63:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         For (i, 1, n * 3) a[i] = read();
      |              ^
a.cc:3:40: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                        ^
a.cc:63:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   63 |         For (i, 1, n * 3) a[i] = read();
      |              ^
a.cc:3:49: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                                 ^
a.cc:65:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |         For (i, 1, n)
      |              ^
a.cc:3:40: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                        ^
a.cc:65:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |         For (i, 1, n)
      |              ^
a.cc:3:49: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                                 ^
a.cc:68:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   68 |         For (i, n + 1, 2 * n) {
      |              ^
a.cc:3:40: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                        ^
a.cc:68:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   68 |         For (i, n + 1, 2 * n) {
      |              ^
a.cc:3:49: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                                 ^
a.cc:74:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   74 |         Fordown (i, n * 3, n * 2 + 1)
      |                  ^
a.cc:4:44: note: in definition of macro 'Fordown'
    4 | #define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
      |                                            ^
a.cc:74:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   74 |         Fordown (i, n * 3, n * 2 + 1)
      |                  ^
a.cc:4:53: note: in definition of macro 'Fordown'
    4 | #define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
      |                                                     ^
a.cc:77:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         Fordown (i, n * 2, n + 1) {
      |                  ^
a.cc:4:44: note: in definition of macro 'Fordown'
    4 | #define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
      |                                            ^
a.cc:77:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         Fordown (i, n * 2, n + 1) {
      |                  ^
a.cc:4:53: note: in definition of macro 'Fordown'
    4 | #define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
      |                                                     ^
a.cc:84:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   84 |         For (i, n, 2 * n)
      |              ^
a.cc:3:40: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                        ^
a.cc:84:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   84 |         For (i, n, 2 * n)
      |              ^
a.cc:3:49: note: in definition of macro 'For'
    3 | #define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
      |                                                 ^
a.cc:88:18: error: expected '}' at end of input
   88 |         return 0;
      |                  ^
a.cc:58:13: note: to match this '{'
   58 | int main () {
      |             ^
a.cc: In instantiation of 'Type pb_ds::read() [with Type = int]':
a.cc:62:10:   required from here
   62 |         n = read();
      |             ~~~~^~
a.cc:32:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         register char ch; register Type ans = 0; register bool neg = 0;
      |                       ^~
a.cc:32:41: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         register char ch; register Type ans = 0; register bool neg = 0;
      |                                         ^~~
a.cc:32:64: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         register char ch; register Type ans = 0; register bool neg = 0;
      |                                                                ^~~