#include <stdio.h>
#include <limits.h>
int main() {
int N;
int a[N+1];
for (int i = 1; i <= N; i++) {
}
int prefix_max[N+1];
int suffix_min[N+1];
prefix_max[0] = INT_MIN;
for (int i = 1; i <= N; i++) {
prefix_max[i] = (a[i] > prefix_max[i-1]) ? a[i] : prefix_max[i-1];
}
suffix_min[N+1] = INT_MAX;
for (int i = N; i >= 1; i--) {
suffix_min[i] = (a[i] < suffix_min[i+1]) ? a[i] : suffix_min[i+1];
}
long long max_S = LLONG_MIN;
for (int j = 2; j < N; j++) {
long long S = 3 * a[j] + 2 * a[j-1] - suffix_min[j+1];
if (S > max_S) {
max_S = S;
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxsaW1pdHMuaD4KCmludCBtYWluKCkgewogICAgaW50IE47CiAgICBzY2FuZigiJWQiLCAmTik7CgogICAgaW50IGFbTisxXTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IE47IGkrKykgewogICAgICAgIHNjYW5mKCIlZCIsICZhW2ldKTsKICAgIH0KCiAgICBpbnQgcHJlZml4X21heFtOKzFdOwogICAgaW50IHN1ZmZpeF9taW5bTisxXTsKCiAgICBwcmVmaXhfbWF4WzBdID0gSU5UX01JTjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IE47IGkrKykgewogICAgICAgIHByZWZpeF9tYXhbaV0gPSAoYVtpXSA+IHByZWZpeF9tYXhbaS0xXSkgPyBhW2ldIDogcHJlZml4X21heFtpLTFdOwogICAgfQoKICAgIHN1ZmZpeF9taW5bTisxXSA9IElOVF9NQVg7CiAgICBmb3IgKGludCBpID0gTjsgaSA+PSAxOyBpLS0pIHsKICAgICAgICBzdWZmaXhfbWluW2ldID0gKGFbaV0gPCBzdWZmaXhfbWluW2krMV0pID8gYVtpXSA6IHN1ZmZpeF9taW5baSsxXTsKICAgIH0KCiAgICBsb25nIGxvbmcgbWF4X1MgPSBMTE9OR19NSU47CiAgICBmb3IgKGludCBqID0gMjsgaiA8IE47IGorKykgewogICAgICAgIGxvbmcgbG9uZyBTID0gMyAqIGFbal0gKyAyICogYVtqLTFdIC0gc3VmZml4X21pbltqKzFdOwogICAgICAgIGlmIChTID4gbWF4X1MpIHsKICAgICAgICAgICAgbWF4X1MgPSBTOwogICAgICAgIH0KICAgIH0KCiAgICBwcmludGYoIiVsbGRcbiIsIG1heF9TKTsKICAgIHJldHVybiAwOwp9Cg==