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.



Sample input:
3
10 40 70
20 50 80
30 60 90


Sample output:
210

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys


def input():
    return sys.stdin.readline().strip()


def main(N, DATA):
    dp = [[0 for _ in range(N)] for _ in range(N + 1)]

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

    res = 0

    for v in range(N):
        res = max(res, dp[N][v])

    return res


if __name__ == '__main__':
    N = int(input())
    DATA = [map(int, input().split()) for i in range(N)]

    
    r = main(N, DATA)
    print(r)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys


def input():
    return sys.stdin.readline().strip()


def main(N, DATA):
    dp = [[0 for _ in range(N)] for _ in range(N + 1)]

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

    res = 0

    for v in range(N):
        res = max(res, dp[N][v])
    print(res)


if __name__ == '__main__':
    N = int(input())
    DATA = [map(int, input().split()) for i in range(N)]

    main(N, DATA)

Submission status: Runtime Error

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main(N, DATA):
    dp = [[0 for _ in range(N)] 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] + DATA[i][k])

    res = 0

    for v in range(N):
        res = max(res, dp[N][v])
    print(res)


if __name__ == '__main__':
    N = int(input())
    DATA = [input().split() for _ in range(N)]
    main(N, DATA)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys


def input():
    return sys.stdin.readline().strip()


def main(N, DATA):
    dp = [[0 for _ in range(N)] for _ in range(N + 1)]

    for i in range(N):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue

                # ここと      ここを比較  ↓比較対象はこれ、j+ k
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + DATA[i][k])

    res = 0

    for v in range(N):
        res = max(res, dp[N][v])
    print(res)


if __name__ == '__main__':
    N = int(input())
    DATA = [input().split() for _ in range(N)]
    # N = 3
    # DATA = [
    #     [10, 40, 70],
    #     [20, 50, 80],
    #     [30, 60, 90]
    # ]
    main(N, DATA)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys


def input():
    return sys.stdin.readline().strip()


def main(N, DATA):
    dp = [[0 for _ in range(N)] for _ in range(N)]

    for i in range(N):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue

                # ここと      ここを比較  ↓比較対象はこれ、j+ k
                dp[i][k] = max(dp[i][k], dp[i][j] + DATA[i][k])

    res = 0

    for v in range(N):
        res = max(res, dp[N - 1][v])
    print(res)


if __name__ == '__main__':
    N = int(input())
    DATA = [input().split() for _ in range(N)]
    # N = 3
    # DATA = [
    #     [10, 40, 70],
    #     [20, 50, 80],
    #     [30, 60, 90]
    # ]
    main(N, DATA)

Submission status: Runtime Error

Solution code:
n = int(input())
h = [list(map(int, input().split())) for _ in input().split()]

x, y, z = 0, 0, 0
for a, b, c in h:
    x, y, z = max(y,z) + a, max(x,z) + b, max(x,y) + c

print(max(x, y, z))

Submission status: Runtime Error

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

a, b, c = 0, 0, 0
for x, y, z in a:
    a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

print(max(a, b, c))

Submission status: Runtime Error

Solution code:
import numpy as np  

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

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, k] = max(dp[i+1, k], dp[i, j] + val[k])

print(int(np.max(dp[n, :], axis=1)))

Submission status: Runtime Error

Solution code:
import numpy as np  

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

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j] + val[k])

print(int(np.max(dp[n, :], axis=1)))

Submission status: Runtime Error

Solution code:
import numpy as np  

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

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j] + val[k])

print(np.max(dp[n, :], axis=1))

Submission status: Runtime Error

Solution code:

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

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j] + val[k])

print(np.max(dp[n, :], axis=1))

Submission status: Runtime Error

Solution code:

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

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = np.max(dp[i+1, j], dp[i, j] + val[k])

print(np.max(dp[n, :], axis=1))

Submission status: Runtime Error

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

dp = [-1]*N

def dfs(i, prev):
    if i >= N:
      return 0
    maxp = -99999999
    for j in range(3):
      if prev == j:
        continue
      maxp = max(maxp, dfs(i+1, j) + T[i][j])
    return maxp

print(dfs(0,-1))

Submission status: Runtime Error

Solution code:
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


def main():
    n = int(input())
    abc = [list(map(int, input().split())) for _ in range(n)]

    dp = [ [0, 0, 0] for _ in range(n) ]

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

    ans = 0
    for i in range(3):
        ans = max(ans, dp[n][i])

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


def main():
    n = int(input())
    abc = [list(map(int, input().split())) for _ in range(n)]

    dp = [ [0, 0, 0] for _ in range(n) ]

    dp[0] = abc[0]

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

    ans = 0
    for i in range(3):
        ans = max(ans, dp[n][i])

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
dp = [map(int, input().split())]
for i in range(n-1):
    a, b, c = map(int, input().split())
    a0 = dp[0]
    b0 = dp[1]
    c0 = dp[2]
    
    dp[0] = max(b0, c0) + a
    dp[1] = max(c0, a0) + b
    dp[2] = max(a0, b0) + c
print(max(dp))

Submission status: Runtime Error

Solution code:
N=int(input())
ABC=[]
for i in range(N):
  l=list(map(int,input().split()))
  ABC=ABC+[l]
dp=[0,0,0]*N#dp[i][j]はi+1日目にアクティビティjを選んだ時の活動終了時の幸福量
for i in range(3):
  dp[0][i]=ABC[0][i]
for i in range(1,N):
  dp[i][1]=max(dp[i-1][2]+ABC[i][1],dp[i-1][0]+ABC[i][1])
  dp[i][0]=max(dp[i-1][1]+ABC[i][0],dp[i-1][2]+ABC[i][0])
  dp[i][2]=max(dp[i-1][1]+ABC[i][2],dp[i-1][0]+ABC[i][2])
ans=max(dp[N-1])
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
ABC=[]
for i in range(N):
  l=list(map(int,input().split()))
  ABC=ABC+[l]
dp=[[0,0,0]*N]#dp[i][j]はi+1日目にアクティビティjを選んだ時の活動終了時の幸福量
for i in range(3):
  dp[0][i]=ABC[0][i]
for i in range(1,N):
  dp[i][1]=max(dp[i-1][2]+ABC[i][1],dp[i-1][0]+ABC[i][1])
  dp[i][0]=max(dp[i-1][1]+ABC[i][0],dp[i-1][2]+ABC[i][0])
  dp[i][2]=max(dp[i-1][1]+ABC[i][2],dp[i-1][0]+ABC[i][2])
ans=max(dp[N-1])
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
ABC=[[0 for i in range(3)]*N]
for i in range(N):
  l=list(map(int,inpujt().split()))
  ABC[i]=l
dp=[[0,0,0] for i in range(N)]#dp[i][j]はi+1日目にアクティビティjを選んだ時の活動終了時の幸福量
dp[0]=max(A[0],B[0],C[0])
for i in range(1,N):
  dp[i][1]=max(dp[i-1][2]+ABC[i][1],dp[i-1][0]+ABC[i][1])
  dp[i][0]=max(dp[i-1][1]+ABC[i][0],dp[i-1][2]+ABC[i][0])
  dp[i][2]=max(dp[i-1][1]+ABC[i][2],dp[i-1][0]+ABC[i][2])
ans=max(dp[N-1])
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
C=[0 for i in range(N)]
for i in range(N):
  a,b,c=map(int,input().split())
  A+=[a]
  B+=[b]
  C+=[c]
dp=[0 for i in range(N)]#dp[i]はi+1日目の活動終了時の幸福量
dpk=[o for i in range(N)]#dpk[i]はi+1日目に選んだアクティビティ
def maxk(n,x):#n番めにxになるもの（a,b,cのいずれか）
  if A[n]==x:
    return a
  elif B[n]==x:
    return b
  elif C[n]==x:
    return c
  else:
    return "error"
dp[0]=max(A[0],B[0],C[0])
dpk[0]=maxk(0,dp[0])
dp[1]=

Submission status: Runtime Error

Solution code:
N = int(input())
A, B, C = [0]*N, [0]*N, [0]*N 
for i in range(N):
    A[i], B[i], C[i] = [int(j) for j in input().split()]

ABC = [A, B, C]
dp = [[0]*3 for _ in range(N+1)]

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

print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
N = int(input())
A, B, C = [0]*N, [0]*N, [0]*N 
for i in range(N):
    A[i], B[i], C[i] = [int(j) for j in input().split()]

dp = [[0]*3 for _ in range(N+1)]
for i in range(N):
    for j in range(3):
        dp[i+1][j] = max(dp[i][j-1], dp[i][j-2]) + ABC[i][j]

print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
# dp[i日目][i-1日目にどれを選んだか] = i日目までの最大の幸福度
n = int(input())
a, b, c = [0 for _ in range(n)], [0 for _ in range(n)], [0 for _ in range(n)]
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

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


def rec(i, choice):
    if dp[i][choice] > 0:
        return dp[i][choice]
    if i == n:
        return 0
    ret = 0  # ループじゃなくてifでやってるのでそれぞれ確実に大きい値が入る（ので更新する必要がない）
    if choice == 0:
        ret = a[i] + max(rec(i + 1, 1), rec(i + 1, 2))
    elif choice == 1:
        ret = b[i] + max(rec(i + 1, 0), rec(i + 1, 2))
    elif choice == 2:
        ret = c[i] + max(rec(i + 1, 0), rec(i + 1, 1))
    dp[i][choice] = ret
    return ret


print(max(rec(0, 0), rec(0, 1), rec(0, 2)))

Submission status: Runtime Error

Solution code:
n = int(input())


days = [] 
for _ in range(n):
  temp = list(map(int,input().split()))
  days.append(temp)
  
dp = [0]*n

for i in range(3):
  dp[i]= days[0][i]
#print(dp) 
for cur_day in range(1,n):
  m = [0]*n
  for i in range(3):
    for j in range(3):
      if i!=j:
        m[i] = max(m[i],dp[j]+days[cur_day][i])
  dp = m
#  print(dp)
  
print(max(dp))

Submission status: Runtime Error

Solution code:
n = int(input())


days = [] 
for _ in range(n):
  temp = list(map(int,input().split()))
  days.append(temp)
  
dp = [0]*n

for i in range(3):
  dp[i]= days[0][i]
#print(dp) 
for cur_day in range(1,n):
  m = [0]*n
  for i in range(3):
    for j in range(3):
      if i!=j:
        m[j] = max(m[j],dp[j]+days[cur_day][i])
  dp = m
#  print(dp)
  
print(max(dp))

Submission status: Runtime Error

Solution code:
n = int(input())


days = [] 
for _ in range(n):
  temp = list(map(int,input().split()))
  days.append(temp)
  
dp = [0]*n

for i in range(3):
  dp[i]= days[0][i]
#print(dp) 
for cur_day in range(1,n):
  m = [0]*n
  for i in range(3):
    for j in range(3):
      if i!=j:
        m[i] = max(m[i],dp[j]+days[cur_day][j])
  dp = m
#  print(dp)
  
print(max(dp))

Submission status: Runtime Error

Solution code:
import numpy as np
INF = float('inf')
MAX_N = 10**5

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

# dp table
# dp[i][j] := 状態jにおけるi日目に得る幸福度の総和の最大値
dp = np.array([[0]*3 for _ in range(N)])

dp[0][0],dp[0][1],dp[0][2] = a[0],b[0],c[0]

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

Submission status: Runtime Error

Solution code:
n = int(input())

a = []
for i in range(n):
  arr = list(map(int, input().split()))
  a.append(arr)

for i in range(0, n):
  for j in range(0, 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[-1]))

Submission status: Runtime Error

Solution code:
#1:初期化
N = int(input())
a = []
r_append = a.append()
for i in range(N):
    r_append(list(map(int,input().split())))
dp = [[0]*3 for _ in range (N+1)]
#print(dp, sep="\n")
#print(a, sep="\n")

#2:初期値(元からゼロなので記述無し)

#3:dp実行部(貰うDP)
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]) #dpは[1]からだが，aは[0]からに注意

#4:出力
dpmax = 0
for i in range(3):
    dpmax= max(dp[N][i], dpmax)
#print(*dp, sep="\n")
print(dpmax)

Submission status: Runtime Error

Solution code:
n=int(input())

ab = []
for _ in range(n):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

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

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

ptint(max(dp[n]))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
d=D
for i in range(n-1):
  for j in d:
    D=d
    D.remove(j)
    C[i+1][j]=max(C[i][D[0]],C[i][D[1]])
print(max(C[n-1]))

Submission status: Runtime Error

Solution code:
N = int(input())
A, B, C = [], [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)

def helper(idx, happy, last):
    if idx >= N:
        return happy
    if last == 'a':
        return max(helper(idx+1, happy+B[idx], 'b'), helper(idx+1, happy+C[idx], 'c'))
    elif last == 'b':
        return max(helper(idx+1, happy+A[idx], 'a'), helper(idx+1, happy+C[idx], 'c'))
    else:
        return max(helper(idx+1, happy+A[idx], 'a'), helper(idx+1, happy+B[idx], 'b'))


happy_a = helper(1, A[0], 'a')
happy_b = helper(1, B[0], 'b')
happy_c = helper(1, C[0], 'c')

print(max(happy_a, happy_b, happy_c))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
d=D
for i in range(n-1):
  for j in d:
    D=d
    D.remove(j)
    C[i+1][j]=C[i][D[0]]+lst[i][D[0]]
    for k in range(1,len(D)):
      if C[i][D[k]]+lst[i][D[k]]>C[i+1][j]:
        C[i+1][j]=C[i][D[k]]+lst[i][D[k]]
print(max(C[n-1]))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
d=D
for i in range(n-1):
  for j in d:
    D=d
    D.remove(j)
    C[i+1][j]=C[i][D[0]]+lst[i][D[0]]
    for k in range(1,len(e)):
      if C[i][D[k]]+lst[i][D[k]]>C[i+1][j]:
        C[i+1][j]=C[i][D[k]]+lst[i][D[k]]
print(max(C[n-1]))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
d=D
for i in range(n-1):
  for j in d:
    D=d
    e=D.remove(j)
    C[i+1][j]=C[i][e[0]]+lst[i][e[0]]
    for k in range(1,len(e)):
      if C[i][e[k]]+lst[i][e[k]]>C[i+1][j]:
        C[i+1][j]=C[i][e[k]]+lst[i][e[k]]
print(max(C[n-1]))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
D=[0,1,2]
d=D
for i in range(1,n-1):
  for j in d:
    e=D.remove(j)
    C[i+1][j]=C[i][e[0]]+lst[i][e[0]]
    for k in range(1,len(e)):
      if C[i][e[k]]+lst[i][e[k]]>C[i+1][j]:
        C[i+1][j]=C[i][e[k]]+lst[i][e[k]]
print(max(C[n-1]))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
for i in range(n):
  a,b,c=map(int,input().split())
  lst.append([a,b,c])
C=[[float('inf')]*3]*n
C[0][0]=lst[0][0]
C[0][1]=lst[0][1]
C[0][2]=lst[0][2]
d=[0,1,2]
for i in range(1,n-1):
  for j in d:
    e=d.remove(j)
    C[i+1][j]=C[i][e[0]]+lst[i][e[0]]
    for k in range(1,len(e)):
      if C[i][e[k]]+lst[i][e[k]]>C[i+1][j]:
        C[i+1][j]=C[i][e[k]]+lst[i][e[k]]
print(min(C[n-1]))

Submission status: Runtime Error

Solution code:
n = int(input())
for _ 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)]
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]+A[i],dp[i-1][2]+A[i])
    dp[i][1] = max(dp[i-1][0]+B[i],dp[i-1][2]+B[i])
    dp[i][2] = max(dp[i-1][0]+C[i],dp[i-1][1]+C[i])
print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

a_b_c_list = []

for i in range(N):
    a_b_c_list.append(list(map(int, input().split())))

dp = [[0 for i in range(3)] for j in range(100)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            if dp[i+1][k] < dp[i][j] + a_b_c_list[i][k]:
                dp[i+1][k] = dp[i][j] + a_b_c_list[i][k]

print(max(dp[N]))

Submission status: Runtime Error

Solution code:
def retMax(a,b):
  if a>=b:
    return a
  else:
    return b

n = int(input())
r = []
dpList = [ [0] * 3 for x in range(n)]

for i in range(n):
  r.append(list(map(int,input().split())))

dpList[0][0] = r[0][0]  
dpList[0][1] = r[0][1]  
dpList[0][2] = r[0][2]  

for s in range(1,n):
  #b->a,c->aの最大値
  dpList[s][0] = retMax(dpList[s-1][1]+r[s][0],dpList[s-1][2]+r[s][0])
  #a->b,c->bの最大値
  dpList[s][1] = retMax(dpList[s-1][0]+r[s][1],dpList[s-1][2]+r[s][1])
  #a->c,b->cの最大値
  dpList[s][2] = retMax(dpList[s-1][0]+r[s][2],dpList[s-1][1]+r[s][2])

print(max(dpList[s]))

Submission status: Runtime Error

Solution code:
N = int(input())
act = [list(map(int, input().split())) for _ in range(N)]
 
import numpy as np
act = np.array(act)
act = np.concatenate([[[0]*3], act])  # 0日目は0にする
 
# DPテーブル
dp = np.zeros([N+1, 3], dtype='int')
 
for i in range(1, N+1):  # 1日目からN日目までの幸福度を順番に計算する
    for j in range(3):  # i日目は海か山か家を選択する
        for k in range(3):  # i日目にjの活動をする場合、i-1日目はj以外の活動
            if k == j:
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k] + act[i][j])
            
print(np.max(dp[-1]))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dp = [[0,-1] for i in range(n+1)]

for i in range(n):
    a = l[i].index(max(l[i]))
    if dp[i][1] == a:
        b = l[i].index(min(l[i]))
        dp[i+1][0],dp[i+1][1] = dp[i][0]+l[i][3-a-b],3-a-b
    else:
        dp[i+1][0],dp[i+1][1] = dp[i][0]+l[i][a],a
    
print(dp[n][0])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dp = [[0,-1] for i in range(n+1)]

for i in range(n):
    a = l[i].index(max(l[i]))
    if dp[i][1] == a:
        b = l[i].index(min(l[i]))
        dp[i+1][0],dp[i+1][1] = dp[i][0]+l[i][3-a-b],3-a-b
    else:
        dp[i+1][0],dp[i+1][1] = dp[i][0]+l[i][a],a
    
print(dp[n][0])

Submission status: Runtime Error

Solution code:
n = int(raw_input())

mat = []
for i in range(n):
    mat.append(map(int,raw_input().split()))
    
dp = [0,0,0]

for day in range(n):
    ndp = [0,0,0]
    data = mat[day]
    
    for i in range(n):
        for j in range(n):
            if i != j:
                ndp[j] = max(ndp[j], dp[i]+data[j])
    dp = ndp
print max(dp)

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
N = 3
A=[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
dp = [[0] * 3 for _ in range(N)]  # 初期化
dp[0] = A[0]  # 初期化
print(dp[0])
for i in range(N-1):
    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-1])

Submission status: Runtime Error

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

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

dp = [[0 for _ in range(3)] for _ in range(1000)]

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]))

Submission status: Runtime Error

Solution code:
N = int(input())

happiness = list(map(int,input().split()))
dp = happiness # dp: i日目にa~cそれぞれの活動をしたときの幸福度の最大値

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] # i日目にaをする場合
    dp[1] = max(dp_pre[0],dp_pre[2])+happiness[1] # i日目にbをする場合
    dp[2] = max(dp_pre[1],dp_pre[0])+happiness[2] # i日目にcをする場合
     
print(max(dp))

Submission status: Runtime Error

Solution code:
# C
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
    na = max(da, dc) + a
    na = max(da, db) + a
    
print(max([na, nb, nc]))

Submission status: Runtime Error

Solution code:
# C
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
    na = max(da, dc) + a
    na = max(da, db) + a
    
print(max(na, nb, nc))

Submission status: Runtime Error

Solution code:
def maxreturn(t,n,a):
    ma=[0]*3
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      b=list(maxreturn(t+1,n,a))
      
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+b[j])
                
    return ma
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))

Submission status: Runtime Error

Solution code:
def maxreturn(t,n,a):
    ma=[0]*3
    b=[0]*3
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      b=list(maxreturn(t+1,n,a))
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+b[j])
                
    return ma
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))

Submission status: Runtime Error

Solution code:
def maxreturn(t,n,a):
    ma=[0]*3
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      a[t+1]=list(maxreturn(t+1,n,a))
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+a[t+1][j])
    
    return ma
    
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))

Submission status: Runtime Error

Solution code:
def maxreturn(t,n,a):
    ma=[0]*3
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      a[t+1]=list(maxreturn(t+1,n,a))
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+a[t+1][j])
    return ma
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))

Submission status: Runtime Error

Solution code:
def maxreturn(t,n,a):
    ma=[0]*n
    b=[0]*n
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      b=list(maxreturn(t+1,n,a))
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+b[j])
                
    return ma
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))

Submission status: Runtime Error

Solution code:
from functools import lru_cache

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))


@lru_cache(None)
def dfs(d,h,pre):
    if d == N - 1:
        return h
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,h + a,idx)
            tmp.append(res)
    return max(tmp)

import sys
sys.setrecursionlimit(10000)

print(dfs(-1,0,-1))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

from functools import lru_cache

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))
@lru_cache(None)
def dfs(d,h,pre):
    if d == N - 1:
        return h
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,h + a,idx)
            tmp.append(res)
    return max(tmp)


print(dfs(-1,0,-1))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))

def dfs(d,h,pre):
    if d == N - 1:
        return h
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,h + a,idx)
            tmp.append(res)
    return max(tmp)


print(dfs(-1,0,-1))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))

def dfs(d,h,pre):
    if d == N - 1:
        return h
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,h + a,idx)
            tmp.append(res)
    return max(tmp)


print(dfs(-1,0,-1))

Submission status: Runtime Error

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

def dfs(d,h,pre):
    if d == N - 1:
        return h
    tmp = [0] 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,h + a,idx)
            tmp.append(res)
    return max(tmp)


print(dfs(-1,0,-1))

Submission status: Runtime Error

Solution code:
n = int(input())
li = []
for i in range(n):
  a = list(map(int, input().split()))
  li.append(a)
dp = []
for i in range(3):
  dp.append([0 for j in range(n)])
dp[0][0] = li[0][0]
dp[0][1] = li[0][1]
dp[0][2] = li[0][2]
for i in range(1, n):
  dp[i][0] = li[i][0] + max(dp[i-1][1], dp[i-1][2])
  dp[i][1] = li[i][1] + max(dp[i-1][0], dp[i-1][2])
  dp[i][2] = li[i][2] + max(dp[i-1][0], dp[i-1][1])
print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))

Submission status: Runtime Error

Solution code:
n = int(inut())
li = []
for i in range(n):
  a = list(map(int, input().split()))
  li.append(a)
dp = []
for i in range(3):
  dp.append([0 for j in range(n)])
dp[0][0] = li[0][0]
dp[0][1] = li[0][1]
dp[0][2] = li[0][2]
for i in range(1, n):
  dp[i][0] = li[i][0] + max(dp[i-1][1], dp[i-1][2])
  dp[i][1] = li[i][1] + max(dp[i-1][0], dp[i-1][2])
  dp[i][2] = li[i][2] + max(dp[i-1][0], dp[i-1][1])
print(max(dp[n][0], dp[n][1], dp[n][2]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

dp = [[-1] * 4 for i in range(N + 1)]


def happy(n, p):
    if n < 0:
        return 0
    if dp[n][p] >= 0:
        return dp[n][p]

    a = 0 if p == 0 else happy(n - 1, 0) + abc[n][0]
    b = 0 if p == 1 else happy(n - 1, 1) + abc[n][1]
    c = 0 if p == 2 else happy(n - 1, 2) + abc[n][2]
    dp[n][p] = max([a, b, c])

    return dp[n][p]


print(happy(N - 1, 3))

Submission status: Runtime Error

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

dp = [[-1] * 4 for i in range(N + 1)]
print(dp)


def happy(n, p):
    if n < 0:
        return 0
    if dp[n][p] >= 0:
        return dp[n][p]

    a = 0 if p == 0 else happy(n - 1, 0) + abc[n][0]
    b = 0 if p == 1 else happy(n - 1, 1) + abc[n][1]
    c = 0 if p == 2 else happy(n - 1, 2) + abc[n][2]
    dp[n][p] = max([a, b, c])

    return dp[n][p]


print(happy(N - 1, 3))