Problem:
 Score : 100 points    Problem Statement Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.  The vacation consists of N days.
For each i ( 1 \leq i \leq N ), Taro will choose one of the following activities and do it on the i -th day:   A: Swim in the sea. Gain a_i points of happiness.  B: Catch bugs in the mountains. Gain b_i points of happiness.  C: Do homework at home. Gain c_i points of happiness.   As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.  Find the maximum possible total points of happiness that Taro gains.      Constraints  All values in input are integers.  1 \leq N \leq 10^5  1 \leq a_i, b_i, c_i \leq 10^4         Input Input is given from Standard Input in the following format:  N  a_1  b_1  c_1  a_2  b_2  c_2  :  a_N  b_N  c_N       Output Print the maximum possible total points of happiness that Taro gains.        Sample Input 1 3
10 40 70
20 50 80
30 60 90      Sample Output 1 210  If Taro does activities in the order C, B, C, he will gain 70 + 50 + 90 = 210 points of happiness.       Sample Input 2 1
100 10 1      Sample Output 2 100       Sample Input 3 7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1      Sample Output 3 46  Taro should do activities in the order C, A, B, A, C, B, A.

Solution (Python):
N = int(input())
scores = []
for i in range(N):
  scores.append(list(map(int, input().split())))
D = scores[0]
for day in range(1, N):
  D = [max(D[:i] + D[i+1:]) + scores[day][i] for i in range(len(D))]

print(max(D))

Solution (Python):
N = int(input())
scores = []
for i in range(N):
  scores.append(list(map(int, input().split())))
D = scores[0]
for day in range(1, N):
  D = [max(D[:i] + D[i+1:]) + scores[day][i] for i in range(len(D))]

print(max(D))

Solution (Python):
n = int(input())
a = [0] * n
for x in range(n):
    a[x] = list(map(int, input().split()))

dp = [[0 for _ in range(3)] for _ in range(n+1)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])

print(max(dp[n]))

Solution (Python):
N = int(input())
abc = [[int(x) for x in input().split()] for _ in range(N)]
dp = [0,0,0] * N

for i in range(N):
  if i == 0:
    dp[0] = abc[0]
    continue

  dp[i] = [abc[i][0]+max(dp[i-1][1],dp[i-1][2]), \
           abc[i][1]+max(dp[i-1][0],dp[i-1][2]), \
           abc[i][2]+max(dp[i-1][0],dp[i-1][1])]
  
print(max(dp[N-1]))

Solution (Python):
n=int(input())
x,y,z=0,0,0
for _ in range(n):
  a,b,c=map(int,input().split())
  x,y,z=a+max(y,z),b+max(z,x),c+max(x,y)
print(max(x,y,z))

Solution (Python):
import sys
 
stdin = sys.stdin
 
mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()
 
n = ni()
 
abc = [na() for i in range(n)]
dp = [3 * [0] for i in range(n)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
 
for i in range(n - 1):
    for j in range(3):
        for k in range(3):
            if k != j:
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i + 1][j])
 
ans = max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])
print(ans)

Solution (Python):
N = int(input())
dp = [[0] * 3 for _ in range(N)]
dp[0][0], dp[0][1], dp[0][2] = map(int, input().split())
for i in range(1,N):
    a, b, c= map(int, input().split())
    dp[i][0] = max(dp[i-1][1]+a,dp[i-1][2]+a)
    dp[i][1] = max(dp[i-1][0]+b,dp[i-1][2]+b)
    dp[i][2] = max(dp[i-1][1]+c,dp[i-1][0]+c)
print(max(dp[N-1]))

Solution (Python):
def solve(n, ABC):
    dp = [[0] * n for _ in range(3)]
    dp[0][0], dp[1][0], dp[2][0] = ABC[0]
    for i in range(1, n):
        for j in range(3):
            dp[j][i] = max(dp[(j + 1) % 3][i - 1], dp[(j + 2) % 3][i - 1]) + ABC[i][j]
    return max(dp[0][n - 1], dp[1][n - 1], dp[2][n - 1])

_n = int(input())
_ABC = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _ABC))

Solution (Python):

from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')

N=int(input())
dp = [[0 for i in range(3)] for j in range(N)]
h=[list(map(int, input().split())) for i in range(N)]
for i in range(N):
    if i == 0:
        dp[0] = h[0]
        continue
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+h[i][j])
print(max(dp[-1]))

Solution (Python):
n = int(input())
abc = [list(map(int, input().split())) for i in range(n)]
a,b,c=abc[0][0],abc[0][1],abc[0][2]
for i in range(1,n):
    a,b,c = abc[i][0]+max(b,c),abc[i][1]+max(a,c),abc[i][2]+max(a,b)
print(max(a,b,c))

Solution (Python):
import sys


def solve():
    readline = sys.stdin.readline
    N = int(readline())
    ABC = (map(int, readline().split()) for _ in range(N))
    x, y, z = 0, 0, 0
    for a, b, c in ABC:
        x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)

    return max(x, y, z)


if __name__ == "__main__":
    answer = solve()
    print(answer)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.readline
    N = int(readline())
    ABC = (map(int, readline().split()) for _ in range(N))
    x, y, z = 0, 0, 0
    for a, b, c in ABC:
        x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)

    return max(x, y, z)


if __name__ == "__main__":
    answer = solve()
    print(answer)

Solution (Python):
N = int(input())

A_list = [0] * N
B_list = [0] * N
C_list = [0] * N

for i in range(N):
    a, b, c = map(int, input().split())
    A_list[i] = a
    B_list[i] = b
    C_list[i] = c

dp = [[0, 0, 0] for j in range(N)]

for i in range(N):
    if i == 0:
        dp[0][0] = A_list[0]
        dp[0][1] = B_list[0]
        dp[0][2] = C_list[0]
    else:
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A_list[i]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B_list[i]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C_list[i]

print(max(dp[N - 1]))

Solution (Python):
N = int(input())

A_list = [0] * N
B_list = [0] * N
C_list = [0] * N

for i in range(N):
    a, b, c = map(int, input().split())
    A_list[i] = a
    B_list[i] = b
    C_list[i] = c

dp = [[0, 0, 0] for j in range(N)]

for i in range(N):
    if i == 0:
        dp[0][0] = A_list[0]
        dp[0][1] = B_list[0]
        dp[0][2] = C_list[0]
    else:
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A_list[i]
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B_list[i]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C_list[i]

print(max(dp[N - 1]))

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    act = np.array([[int(item) for item in input().split()] for _ in range(N)])

    dp = np.zeros((2, 3), dtype='int64')
    selector = np.array([[0,1,1], [1,0,1], [1,1,0]])

    for i in range(0,N):
        
        
        dp[i%2^1] = np.max(dp[i%2]*selector, axis=1) + act[i]
        

    print(max(dp[N%2]))

main()

Solution (Python):
N = int(input())
A = []
for i in range(N):
  line1 = [int(i) for i in input().split()]
  A.append(line1)
mem = [[0] * 3 for i in range(N)]
mem[0][0] = A[0][0]
mem[0][1] = A[0][1]
mem[0][2] = A[0][2]
for i in range(1, N):
  mem[i][0] = max(mem[i-1][1], mem[i-1][2]) + A[i][0]
  mem[i][1] = max(mem[i-1][0], mem[i-1][2]) + A[i][1]
  mem[i][2] = max(mem[i-1][0], mem[i-1][1]) + A[i][2]
print("%s" % max(mem[N-1]))

Solution (Python):
N = int(input())
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
    A[i], B[i], C[i] = map(int, input().split())
dp = [[0] * 3 for _ in range(N)]  
dp[0] = [A[0], B[0], C[0]]

for i in range(N-1):
    dp[i+1][0] = max(dp[i][1]+A[i+1], dp[i][2]+A[i+1])
    dp[i+1][1] = max(dp[i][0]+B[i+1], dp[i][2]+B[i+1])
    dp[i+1][2] = max(dp[i][0]+C[i+1], dp[i][1]+C[i+1])
print(max(dp[N-1]))

Solution (Python):
N = int(input())
Y = []
for _ in range(N):
    Y.append(list(map(int, input().split())))  
dp = [[0] * 3 for _ in range(N)]  
dp[0] = Y[0]  


for i in range(N-1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k] + Y[i+1][j])
print(max(dp[N-1]))

Solution (Python):
n = int(input())
ABCs = [list(map(int, input().split())) for i in range(n)]

last = -1

dp = [[None]*3 for i in range(n)]
dp[0] = [0,0,0]




for i in range(n+1):
    if i == 0:
        continue
    if i == 1:
        dp[i-1][0] = ABCs[i-1][0]
        dp[i-1][1] = ABCs[i-1][1]
        dp[i-1][2] = ABCs[i-1][2]
        continue
    for j in range(3):

        actions = ABCs[i-1]

        
    
        dp[i-1][j] = max([dp[i-2][k] for k in range(3) if k != j]) + ABCs[i-1][j]

print(max(dp[n-1]))

Solution (Python):
def edpcC(n, abcs):
    coidx = ((1, 2), (2, 0), (0, 1))
    dp = [abcs[0]]
    for i in range(1, n):
        prev_dp = dp[i-1]
        cur_vals = abcs[i]
        new_d = []
        for j in range(3):
            tmp = [cur_vals[j][1] + p[1] for p in (prev_dp[c] for c in coidx[j])]
            new_d.append((j, max(tmp)))
        dp.append(new_d)
    print(max(dp[-1], key=lambda x:x[1])[1])
    
n = int(input())
abcs = [list(enumerate(map(int, input().split(' ')))) for _ in range(n)]
edpcC(n, abcs)

Solution (Python):
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()

abc = [na() for i in range(n)]
dp = [3 * [0] for i in range(n)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(n - 1):
    for j in range(3):
        for k in range(3):
            if k != j:
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i + 1][j])

ans = max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2])
print(ans)

Solution (Python):
N=int(input())

a=[0]*N
b=[0]*N
c=[0]*N

flag = -1
for i in range(N):
    a[i],b[i],c[i] = map(int,input().split())

dp=[[0]*3 for i in range(N)]

for i in range(N):
    if i==0:
        dp[i][0]=a[i]
        dp[i][1]=b[i]
        dp[i][2]=c[i]
    else:
        dp[i][0]=a[i] + max(dp[i-1][1],dp[i-1][2])
        dp[i][1]=b[i] + max(dp[i-1][2],dp[i-1][0])
        dp[i][2]=c[i] + max(dp[i-1][0],dp[i-1][1])
print(max(dp[N-1]))

Solution (Python):

N = int(input())
a = []
for i in range(N):
    a.append(list(map(int,input().split())))
dp = [[0]*3 for _ in range (N+1)]






for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if(j == k):
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i-1][j]) 


dpmax = 0
for i in range(3):
    dpmax= max(dp[N][i], dpmax)

print(dpmax)

Solution (Python):

N = int(input())
a = []
for i in range(N):
    a.append(list(map(int,input().split())))
dp = [[0]*3 for _ in range (N+1)]






for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if(j == k):
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i-1][j]) 


dpmax = 0
for i in range(3):
    dpmax= max(dp[N][i], dpmax)

print(dpmax)

Solution (Python):
n = int(input())
v = [ list(map(int, input().split())) for _ in range(n) ]
dp = [ [0]*3 for _ in range(n) ]
for i in range(n):
  for j in range(3):
    if i == 0:
      dp[i][j] = v[i][j]
    else:
      for k in range(3):
        if j != k:
          dp[i][j] = max(dp[i][j], dp[i-1][k]+v[i][j])
print(max(dp[n-1]))

Solution (Python):
n=int(input())
a=[0]*n
b=[0]*n
c=[0]*n
for i in range(n):
    a[i],b[i],c[i]=map(int,input().split())

dp=[[0,0,0] for _ in range(n+1)]
for i in range(1,n+1):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i-1]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i-1]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i-1]

print(max(dp[n]))

Solution (Python):
N = int(input())
H = []
for i in range(N):
    H.append(list(map(int, input().split())))

dp = [[0]*3 for _ in range(N)]
dp[0] = H[0]
for i in range(1,N):
    for j in range(3):
        dp[i][j] = H[i][j] + max(dp[i-1][k] for k in range(3) if k != j)
print(max(dp[N-1]))

Solution (Python):
N = int(input())
P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

dp = [[0 for _ in range(3)] for _ in range(10**5)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if k == j:
                continue
            dp[i][k] = max(dp[i][k], dp[i-1][j] + P[i][k])
            
print(max(dp[N-1]))

Solution (Python):
N = int(input())

happiness = list(map(int,input().split()))
dp = happiness 

for i in range(1,N):
    happiness = list(map(int,input().split()))
    dp_pre = dp.copy()

    dp[0] = max(dp_pre[1],dp_pre[2])+happiness[0] 
    dp[1] = max(dp_pre[0],dp_pre[2])+happiness[1] 
    dp[2] = max(dp_pre[1],dp_pre[0])+happiness[2] 
     
print(max(dp))

Solution (Python):
n = int(input())
x,y,z = 0,0,0
for _ in range(n):
    a,b,c = map(int,input().split())
    x,y,z = a + max(y,z), b + max(x,z), c + max(x,y)
print(max(x,y,z))

Solution (Python):
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dp = [[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i-1]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i-1]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i-1]

print(max(dp[n]))

Solution (Python):
N = int(input())

dp = [[None]*3 for n in range(N+1)]
dp[0] = [0, 0, 0]

for n in range(1, N+1):
    act = list(map(int, input().split()))
    dp[n][0] = max(dp[n-1][1], dp[n-1][2]) + act[0]
    dp[n][1] = max(dp[n-1][2], dp[n-1][0]) + act[1]
    dp[n][2] = max(dp[n-1][0], dp[n-1][1]) + act[2]

print(max(dp[N]))

Solution (Python):
N = int(input())
a = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    t = list(map(int, input().split()))
    for j in range(3):
        a[i][j] = t[j]

dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])



answer = 0
for j in range(3):
    answer = max(answer, dp[N][j])

print(answer)

Solution (Python):
N = int(input())
H = []
for _ in range(N):
    H.append(tuple(map(int, input().split())))

table = [[0] * 3 for _ in range(N)]
st = set(range(3))
for n in range(N):
    table[n] = [H[n][i] + max(table[n - 1][j] for j in (st - {i})) for i in st]

print(max(table[N - 1]))

Solution (Python):
n=int(input())
old=[0,0,0]
new=[0,0,0]
for i in range(n):
    a,b,c=map(int,input().split())
    new[0]=a+max(old[1],old[2])
    new[1]=b+max(old[2],old[0])
    new[2]=c+max(old[0],old[1])
    old=new[:]

print(max(new))

Solution (Python):
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
b=[0]*3
for i in range(n-2,-1,-1):
    for j in range(3):
        t=0
        for k in range(3):
            if j!=k:
                t=max(t,a[i][j]+a[i+1][k])
        a[i][j]=t
print(max(a[0]))

Solution (Python):
def main():
    N = int(input())
    abc = [list(map(int,input().split())) for _ in range(N)]
    abc.insert(0,[0,0,0])
    dp = [[0]*3 for _ in range(N+1)]
    for i in range(1,N+1):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i][j] = max(dp[i][j],dp[i-1][k]+abc[i][j])
    print(max(dp[N]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    l=[]
    for i in range(N):
        l.append(list(map(int,input().split())))
    dp=[[0]*3 for _ in range(N+1)]
    for i in range(N):
        for k in range(3):
            dp[i+1][k]=max(dp[i][(k+1)%3]+l[i][k],dp[i][(k+2)%3]+l[i][k])
    print(max(dp[N]))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

what_to_do = []
for i in range(N):
    input2 = input().split()
    tmp1,tmp2,tmp3 = list(map(int,input2))
    what_to_do.append([tmp1,tmp2,tmp3])

dp = []
for _ in range(N+1):
    dp.append([0,0,0])

for i in range(N):
    for k in range(3):
        for j in range(3):
            if k != j:
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + what_to_do[i][k])
                
            
print(max(dp[-1]))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    N = Scanner.int()
    A = [Scanner.map_int() for _ in range(N)]
    dp = [[0 for _ in range(3)] for _ in range(N)]
    dp[0][0], dp[0][1], dp[0][2] = A[0]
    for i in range(1, N):
        for c in range(3):
            dp[i][c] = max(dp[i][c], dp[i-1][(c+1) % 3] + A[i][c])
            dp[i][c] = max(dp[i][c], dp[i-1][(c+2) % 3] + A[i][c])
    print(max(dp[N-1]))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
lis = [list(map(int,input().split())) for _ in range(n)]





dp = [[lis[0][0]]+[0]*(n-1),[lis[0][1]]+[0]*(n-1),[lis[0][2]]+[0]*(n-1)]


for j in range(n):
    if j == 0:
        continue
    for i in range(3):
        if i == 0:
            dp[i][j] = max(dp[1][j-1],dp[2][j-1])+lis[j][i]
        if i == 1:
            dp[i][j] = max(dp[0][j-1],dp[2][j-1])+lis[j][i]
        if i == 2:
            dp[i][j] = max(dp[0][j-1],dp[1][j-1])+lis[j][i]



print(max(dp[0][n-1],dp[1][n-1],dp[2][n-1]))

Solution (Python):
def get_vacation(vacation_data):
    A, B, C = range(3)
    dp = [[-1 for i in range(3)] for j in range(len(vacation_data))]
    dp[0] = vacation_data[0]
    for i in range(1, len(vacation_data)):
        a, b, c = vacation_data[i]
        dp[i][A] = max(dp[i - 1][B], dp[i - 1][C]) + a
        dp[i][B] = max(dp[i - 1][A], dp[i - 1][C]) + b
        dp[i][C] = max(dp[i - 1][A], dp[i - 1][B]) + c
    return max(dp[-1])


def get_input():
    n = int(input())
    data = []
    for i in range(n):
        el = list(map(int, input().split()))
        data.append(el)
    return data
 
data = get_input()
print(get_vacation(data))

Solution (Python):


days = int(input())
mat = [[0 for x in range(3)] for y in range(days)] 
a = [[0 for x in range(3)] for y in range(days)] 


for day in range(days):
    ln = input()
    ln = ln.split()
    for act in range(0,3):
        a[day][act] = int(ln[act])
        
        

for i in range(0,days):
    for act in range(0,3):
        if(i==0):
           mat[i][act] = a[i][act]
        else:
            if(act == 0):
                mat[i][0] = max(mat[i-1][1] + a[i][act],  mat[i-1][2] + a[i][act])
            elif(act == 1):
                mat[i][1] = max(mat[i-1][0] + a[i][act],  mat[i-1][2] + a[i][act])
            elif(act == 2):        
                mat[i][2] = max(mat[i-1][1] + a[i][act],  mat[i-1][0] + a[i][act])
        
        
pts = max(mat[days-1][0], mat[days-1][1])  
pts = max(pts, mat[days-1][2])
print(pts)

'''    
a= [int(act) for act in input().split()]
'''

Solution (Python):


import fractions 
import functools 

import sys
sys.setrecursionlimit(200000000)

def pin(type=int):
    return map(type,input().split())
"""
------------------------------------------------------------------
|OBJECTIVE:                                                      |
|Educatinal DP contest("https://atcoder.jp/contests/dp")を解こう!|
------------------------------------------------------------------
"""

INF = float("inf")
"""
|
|   つまり、漸化式みたいに i回目までの結果を保存して、i+1回目の評価を行う
"""
def Flog_1(N,H):
    dp=[INF for i in range(N)]
    dp[0]=0  
    dp[1]=abs(H[1]-H[0])
    for i in range(2,N):
        hop1=dp[i-1]+abs(H[i-1]-H[i]) 
        hop2=dp[i-2]+abs(H[i-2]-H[i]) 
        
        dp[i]=hop1 if hop1<hop2 else hop2
    return dp
def Flog_1_Another(N,H):
    dp=[INF for i in range(N)]
    dp[0]=0  
    for i in range(0,N):
        for k in [1,2]:
            if i+k <N:
                dp[i+k]=min(dp[i+k],dp[i]+abs(H[i+k]-H[i]))
    return dp
"""
|
|    
"""    
def Flog_2(N,K,H):
    dp=[INF for i in range(N)]
    dp[0]=0  
    for i in range(1,N):
        temp = INF
        for k in range(1,K+1):
            if i-k < 0:break
            else:
                
                temp = min(temp,(dp[i-k]+abs(H[i-k]-H[i])))
                
        dp[i]=temp
        
    return dp
def Flog_2_Another(N,K,H):
    dp=[INF for i in range(N)]
    dp[0]=0  
    for i in range(0,N):
        for k in range(1,K+1):
            if i+k <N:
                dp[i+k]=min(dp[i+k],dp[i]+abs(H[i+k]-H[i]))
    return dp
def Flog_2_YETAnother(N,K,H):
    
    if N == 1:
        return 0
    else:
        map(min,[Flog_2_YETAnother(N-i,K,H) for i in range(1,N+1)])
    

def vacation(N):
    
    dp=[[0]*3 for i in range(N)]
    dp[0]=list(pin())
    
    for i in range(1,N):
        
        temp=list(pin())
       
        dp[i][0]= max(dp[i-1][1],dp[i-1][2])+temp[0]
        dp[i][1]= max(dp[i-1][2],dp[i-1][0])+temp[1]
        dp[i][2]= max(dp[i-1][0],dp[i-1][1])+temp[2]
        
    return max(dp[-1])

N,=pin()


print(vacation(N))

Solution (Python):


n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

dp=[[0]*3 for i in range(n)]
dp[0]=l[0]


for i in range(1,n):
    for j in range(3):
        for k in range(3):
            
            if j!=k:
                dp[i][j]=max(dp[i-1][k]+l[i][j],dp[i][j])
print(max(dp[-1]))

Solution (Python):

N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    nb = max(da, dc) + b
    nc = max(da, db) + c
    da = na
    db = nb
    dc = nc
    
print(max([na, nb, nc]))

Solution (Python):
import sys

input = sys.stdin.readline

n = int(input())

abc = [[int(i) for i in input().split()] for j in range(n)]

def happy(n, abc):
    da, db, dc = 0, 0, 0
    
    for a, b, c in abc:
        na = max(db, dc) + a
        nb = max(da, dc) + b
        nc = max(da, db) + c
        
        da, db, dc = na, nb, nc
    
    return max(da, db, dc)
    
print(happy(n, abc))

Solution (Python):
N = int(input())
arr = [[0]*3 for _ in range(N)]
"""
a = [0]*N
b = [0]*N
c = [0]*N
"""
for i in range(N):
    arr[i]=list(map(int,input().split()))
    

dp = [[-1]*3 for _ in range(N)]

dp[0] = arr[0]

for i in range(1,N):
    for j in range(3):
        k = (j+1)%3
        l = (j+2)%3
        dp[i][j] = max(dp[i-1][k]+arr[i][j],dp[i-1][l]+arr[i][j])

ans = max(dp[-1])
print(ans)

Solution (Python):
import sys
n = int(sys.stdin.readline().strip('\n'))
a = [list(map(int, sys.stdin.readline().strip('\n').split())) for _ in range(n)]

dp = [[0 for _ in range(3)] for _ in range(n+1)]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if j==k: continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])

print(max(dp[n]))

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
dp=[[0]*3 for i in range(n)]

dp[0]=l[0]

for i in range(1,n):
    for j in range(3):
        for k in range(3):
            if j!=k:
                dp[i][j]=max(dp[i][j],dp[i-1][k]+l[i][j])
print(max(dp[-1]))

Solution (Python):
N = int(input())

abc = []
for i in range(N):
    tmp = list(map(int, input().split()))
    abc.append(tmp)
    
dp = [[0]*3 for i in range(N+1)]
for i in range(N):
    a, b, c = abc[i]
    dp[i+1][0] += max(dp[i][1] + a, dp[i][2] + a)
    dp[i+1][1] += max(dp[i][0] + b, dp[i][2] + b)
    dp[i+1][2] += max(dp[i][0] + c, dp[i][1] + c)
                
print(max(dp[N]))

Solution (Python):
N = int(input())
dp = [[0] * 3 for _ in range(N)]
action = list(map(int, input().split()))
dp[0][0] = action[0]
dp[0][1] = action[1]
dp[0][2] = action[2]
for i in range(N-1):
    action = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1]+action[0],dp[i][2]+action[0])
    dp[i+1][1] = max(dp[i][0]+action[1],dp[i][2]+action[1])
    dp[i+1][2] = max(dp[i][0]+action[2],dp[i][1]+action[2])
print(max(dp[N-1]))

Solution (Python):
N = int(input())
act = [[int(item) for item in input().split()] for _ in range(N)]

dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        temp_hp = []
        for k in range(3):
            if k != j:
                temp_hp.append(dp[i-1][k] + act[i][j])
        dp[i][j] = max(temp_hp)

print(max(dp[N-1]))

Solution (Python):
n, *t = map( int, open( 0 ).read().split() )
 

A, B, C = 0, 0, 0
for i in  range( n ):
  A, B, C = t[ 3 * i  ] + max( B, C ), t[ 3 * i + 1 ] + max( A, C ), t[ 3 * i + 2 ] + max( A, B )
 
print( max( A, B, C ) )

Solution (Python):
import numpy as np
N = int(input())

abc = np.array([list(map(int, input().split())) for i in range(N)])

dp = [[0]*3 for i in range(N+1)]

for i in range(1, N+1):
    dp[i][0] = max(dp[i - 1][1] + abc[i - 1][1], dp[i - 1][2] + abc[i - 1][2])
    dp[i][1] = max(dp[i - 1][0] + abc[i - 1][0], dp[i - 1][2] + abc[i - 1][2])
    dp[i][2] = max(dp[i - 1][1] + abc[i - 1][1], dp[i - 1][0] + abc[i - 1][0])

print(max(dp[-1]))

Solution (Python):
import numpy as np
N = int(input())

abc = np.array([list(map(int, input().split())) for i in range(N)])

dp = [[0]*3 for i in range(N+1)]

for i in range(1, N+1):
    dp[i][0] = max(dp[i - 1][1] + abc[i - 1][1], dp[i - 1][2] + abc[i - 1][2])
    dp[i][1] = max(dp[i - 1][0] + abc[i - 1][0], dp[i - 1][2] + abc[i - 1][2])
    dp[i][2] = max(dp[i - 1][1] + abc[i - 1][1], dp[i - 1][0] + abc[i - 1][0])

print(max(max(dp)))

Solution (Python):

n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int, input().split())

'''
前日までの選択による最大値が分かれば、当日の最適選択ができる
dpテーブルを３枠用意する形にして、下から順に更新していけば良い
'''


dp = []
dp.append([a[0],b[0],c[0]])


for i in range(1,n):
    dp.append( [ \
        a[i] + max(dp[i-1][1],dp[i-1][2]), \
        b[i] + max(dp[i-1][0],dp[i-1][2]), \
        c[i] + max(dp[i-1][0],dp[i-1][1])  \
        ] )

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))

Solution (Python):
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]
dp = [[0, 0, 0] for _ in range(n)]
dp[0][:] = s[0][:]
for i in range(1, n):
    for j in range(3):  
        for k in range(3):  
            if j != k:
                try:
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + s[i][j])
                except:
                    pass

print(max(dp[-1][:]))

Solution (Python):
n = int(input())
h = [list(map(int, input().split())) for _ in range(n)]
dp = [[0, 0, 0] for _ in range(2)]
for i, (a, b, c) in enumerate(h):
    dp[i % 2][0] = a + max(dp[1 - i % 2][1], dp[1 - i % 2][2])
    dp[i % 2][1] = b + max(dp[1 - i % 2][0], dp[1 - i % 2][2])
    dp[i % 2][2] = c + max(dp[1 - i % 2][0], dp[1 - i % 2][1])
print(max(dp[i % 2]))

Solution (Python):
N=int(input())
List=[list(map(int,input().split())) for i in range(N)]
A,B,C=zip(*List)
dp=[[0]*3 for i in range(N)]
dp[0][0]=A[0]
dp[0][1]=B[0]
dp[0][2]=C[0]
for i in range(1,N):
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i]
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+B[i]
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+C[i]
print(max(dp[-1]))

Solution (Python):
N=int(input())
List=[list(map(int,input().split())) for i in range(N)]
A,B,C=zip(*List)
dp=[[0]*3 for i in range(N)]
dp[0][0]=A[0]
dp[0][1]=B[0]
dp[0][2]=C[0]
for i in range(1,N):
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i]
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+B[i]
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+C[i]
print(max(dp[-1]))

Solution (Python):
N = int(input())
x = [[0,0,0]]*N
for i in range(N):
	x[i] = list(map(int,input().split()))



dp = [[0,0,0] for i in range(N)]

dp[0] = x[0]

for i in range(1,N):
	for j in range(3):
		for k in range(3):
			
			if j != k:
				dp[i][j] = max(dp[i][j],dp[i-1][k]+x[i][j])

print(max(dp[N-1]))

Solution (Python):
import sys
input = sys.stdin.readline  

N = int(input())
a,b,c = map(int,input().split())
dp = [[a,b,c]]
for i in range(N-1):
    a,b,c = map(int,input().split())
    A = max(dp[i][1]+a,dp[i][2]+a)
    B = max(dp[i][2]+b,dp[i][0]+b)
    C = max(dp[i][0]+c,dp[i][1]+c)
    dp.append([A,B,C])
print(max(dp[-1]))

Solution (Python):
n = int(input())
A,B,C = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)

dp = [[0]*3 for i in range(n+1)]
for i in range(n):
    dp[i+1][0] = max(max( dp[i][1], dp[i][2] ) + A[i] ,dp[i+1][0])
    dp[i+1][1] = max(max( dp[i][0], dp[i][2] ) + B[i] ,dp[i+1][1])
    dp[i+1][2] = max(max( dp[i][0], dp[i][1] ) + C[i] ,dp[i+1][2])
    
print(max(dp[-1]))

Solution (Python):
N = int(input())
X=[list(map(int,input().split())) for i in range(N)]

dp = [[0] * 3 for _ in range(N+1)]
for i in range(N):
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + X[i][j])	
ans=0
for j in range(3):
  ans=max(ans,dp[N][j])
print(ans)

Solution (Python):
N = int(input())
X=[list(map(int,input().split())) for i in range(N)]

dp = [[0] * 3 for _ in range(N+1)]
for i in range(N):
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + X[i][k])	
ans=0
for j in range(3):
  ans=max(ans,dp[N][j])
print(ans)

Solution (Python):
n = int(input())
abcl = []
for _ in range(n):
   a,b,c = map(int,input().split())
   abcl.append((a,b,c))
dp = [[float("inf") for _ in range(3)] for _ in range(n)]

dp[0][0] = abcl[0][0]
dp[0][1] = abcl[0][1]
dp[0][2] = abcl[0][2]

for i in range(n-1):
    a,b,c = abcl[i+1]
    dp[i+1][0] = max(dp[i][1]+a, dp[i][2]+a)
    dp[i+1][1] =  max(dp[i][0]+b, dp[i][2]+b)
    dp[i+1][2] =  max(dp[i][0]+c, dp[i][1]+c)

print(max(dp[-1][0], dp[-1][1], dp[-1][2]))