#include using namespace std; #define ll long long #define pii pair #define pll pair #define vi vector #define vl vector #define ov4(a, b, c, d, name, ...) name #define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c)) #define rep2(i, a, b) rep3(i, a, b, 1) #define rep1(i, n) rep2(i, 0, n) #define rep0(n) rep1(aaaaa, n) #define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define per(i, a, b) for(ll i = (a) - 1; i >= (b); i--) #define fore(e, v) for(auto &&e : v) #define all(a) begin(a), end(a) #define si(a) (int)(size(a)) #define lb(v, x) (lower_bound(all(v), x) - begin(v)) #define eb emplace_back template bool chmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } template bool chmax(T &a, const S &b) { return a < b ? a = b, 1 : 0; } const int INF = 1e9 + 100; const ll INFL = 3e18 + 100; #define i128 __int128_t struct _ { _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); } } __; int main() { int n; cin >> n; vl a(n), b(n), c(n); fore(e, a) cin >> e; fore(e, b) cin >> e; fore(e, c) cin >> e; ll ma = 0; // 0 (1 or 2) 0 vector dp(n + 1, vl(3, -INFL)); dp[0][0] = dp[0][1] = dp[0][2] = 0; rep(i, n) { chmax(dp[i + 1][0], dp[i][0] + a[i]); chmax(dp[i + 1][1], max(dp[i][0] + a[i], dp[i][1] + max(b[i], c[i]))); chmax(dp[i + 1][2], max(dp[i][1] + max(b[i], c[i]), dp[i][2] + a[i])); } chmax(ma, *max_element(all(dp[n]))); // 0 1 0 1 0 dp = vector(n + 1, vl(5, -INFL)); rep(j, 5) dp[0][j] = 0; rep(i, n) { chmax(dp[i + 1][0], dp[i][0] + a[i]); rep(j, 1, 5) { chmax(dp[i + 1][j], dp[i][j - 1] + (j & 1 ? a[i] : b[i])); chmax(dp[i + 1][j], dp[i][j] + (~j & 1 ? a[i] : b[i])); } } chmax(ma, *max_element(all(dp[n]))); cout << ma << endl; }