namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { object? Solve() { var n = Int(); var xz = 3.Repeat(() => n.Repeat(Int)); var min = long.MinValue / 8; var dp = new long[3, 3]; for (var i = 0; i < 3; i++) for (var j = 0; j < 3; j++) dp[i, j] = min; dp[0, 0] = 0; for (var k = 0; k < n; k++) { var ep = new long[3, 3]; for (var i = 0; i < 3; i++) for (var j = 0; j < 3; j++) ep[i, j] = min; for (var i = 0; i < 3; i++) for (var j = 0; j < 3; j++) { var v = dp[i, j]; ep[i, j] = Math.Max(ep[i, j], v + xz[i][k]); if (i + 1 < 3 && j + 1 < 3) ep[i + 1, j + 1] = Math.Max(ep[i + 1, j + 1], v + xz[i + 1][k]); if (i + 2 < 3 && j + 2 < 3) ep[i + 2, j + 2] = Math.Max(ep[i + 2, j + 2], v + xz[i + 2][k]); if (i >= 1) ep[i - 1, j] = Math.Max(ep[i - 1, j], v + xz[i - 1][k]); if (i >= 2) ep[i - 2, j] = Math.Max(ep[i - 2, j], v + xz[i - 2][k]); } dp = ep; } var ans = min; for (var i = 0; i < 3; i++) for (var j = 0; j < 3; j++) ans = Math.Max(ans, dp[i, j]); return ans; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Trim().Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } }