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:
def pathSmMax(matrix,i,j,cache):
    if i > len(matrix)-1: return 0
    happiness = 0
    if cache[i][j] != 0:
        return cache[i][j]
    for k in range(3):
        if k != j:
            happiness = max(happiness,pathSmMax(matrix,i+1,k,cache) + matrix[i][j])
    cache[i][j] = happiness
    return cache[i][j]
N = int(input())
matrix = []
for i in range(N):
	matrix.append([int(i) for i in input().split()])
maxs = -float("inf")
cache = [[0 for i in range(4)] for j in range(len(matrix)+1)]
for i in range(len(matrix)):
    maxs = max(maxs,pathSmMax(matrix,0,i,cache))
print(maxs)

Submission status: Runtime Error

Solution code:
def pathSmMax(matrix,i,j,cache):
    if i < 0 or j < 0 or i > len(matrix)-1 or j > len(matrix[0])-1: return 0
    happiness = -float("inf")
    if cache[i][j] != 0:
        return cache[i][j]
    for k in range(3):
        if k != j:
            happiness = max(happiness,pathSmMax(matrix,i+1,k,cache) + matrix[i][j])
    cache[i][j] = happiness
    return cache[i][j]
N = int(input())
matrix = []
for i in range(N):
    matrix.append([int(i) for i in input().split()])
maxs = -float("inf")
cache = [[0 for i in range(len(matrix[0])+1)] for j in range(len(matrix)+1)]
for i in range(len(matrix)):
    maxs = max(maxs,pathSmMax(matrix,0,i,cache))
print(maxs)

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
	satis.extend(map(int,input().split()))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
  A=list(map(int,input().split()))
  satis.extend(A)

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
  satis += map(int,input().split())

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
  satis += list(map(int,input().split()))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
	satis += list(map(int,input().split()))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
	satis.extend(list(map(int,input().split())))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

for i in range(n):
	satis.extend(;istmap(int,input().split())))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

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

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]
 
for i in range(n):
	satis.append(map(int,input().split()))
 
#n=3
#satis=[10, 40, 70, 20, 50, 80, 30, 60, 90]
 
tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]
 
for i in range(n):
	satis.append(map(int,input().split()))
 
#n=3
#satis=[10, 40, 70, 20, 50, 80, 30, 60, 90]
 
tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
   print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]
 
for i in range(n):
	satis.append(list(map(int,input().split())))
 
#n=3
#satis=[10, 40, 70, 20, 50, 80, 30, 60, 90]
 
tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
   print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]
 
for i in range(n):
	satis.append(list(map(int,input().split())))
 
#n=3
#satis=[10, 40, 70, 20, 50, 80, 30, 60, 90]
 
tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    print([satis[3*i+3],satis[3*i+4],satis[3*i+5]])
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

Solution code:
n=input()
satis=[]

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

#n=3
#satis=[10, 40, 70, 20, 50, 80, 30, 60, 90]

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    print([satis[3*i+3],satis[3*i+4],satis[3*i+5]])
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
else:
  print(max([tempA,tempB,tempC]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
 
m ={}
def dp(i, a, b, c):
	if (i,a,b,c) in m:
		return m[(i,a,b,c)]
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	m[(i,a,b,c)] = max([a_v, b_v, c_v])
	return max([a_v, b_v, c_v])
 
al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))

Submission status: Runtime Error

Solution code:
n = int(input())

def dp(i, a, b, c):
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	return max([a_v, b_v, c_v])

al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))

Submission status: Runtime Error

Solution code:
s=0,t=-1
for _ in range(int(input())):
    a,b,c=map(int,input().split())
    if t==1:
        if b>c:
            s+=b
            t=2
        else:
            s+=c
            t=3
    elif t==2:
        if a>c:
            s+=a
            t=1
        else:
            s+=c
            t=3
    elif t==3:
        if a>b:
            s+=a
            t=1
        else:
            s+=b
            t=2
    else:
        s+=max(a,b,c)
print(s)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)

N = int(input())
D = []
dp = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])
    dp.append([-1]*3)

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if dp[n][activity]!=-1:
        return dp[n][activity]
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
            dp[n][activity] = ans
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    dp[n][activity] = ans
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000000)

N = int(input())
D = []
dp = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])
    dp.append([-1]*3)

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if dp[n][activity]!=-1:
        return dp[n][activity]
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
            dp[n][activity] = ans
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    dp[n][activity] = ans
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

N = int(input())
D = []
dp = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])
    dp.append([-1]*3)

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if dp[n][activity]!=-1:
        return dp[n][activity]
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    dp[n][activity] = ans
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

N = int(input())
D = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Submission status: Runtime Error

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

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A, B, C = np.full((3,N),0)

    for i in range(N):
        A[i], B[i], C[i] = [int(x) for x in input().split()]

    DP = [[0]*3]*N

    act = [A,B,C]

    for i, X in enumerate(act):
        DP[0][i] = X[0]
    
    for i in range(N-1):
        for x, X in enumerate(act):
            for y, Y in enumerate(act):
                if x != y:
                    DP[i+1][y] = max(DP[i+1][y],DP[i][x]+Y[i+1])

    print(DP[-1].max())

if __name__ == "__main__":
    main()
    pass

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    N = int(input())
    A, B, C = np.zeros((N,3))

    for i in range(N):
        A[i], B[i], C[i] = [int(x) for x in input().split()]

    DP = np.full((N,3),-float("inf"),dtype=int)

    act = [A,B,C]

    for i, X in enumerate(act):
        DP[0][i] = X[0]
    
    for i in range(N-1):
        for x, X in enumerate(act):
            for y, Y in enumerate(act):
                if x != y:
                    DP[i+1][x] = max(DP[i+1][x],DP[i][y]+Y[i+1])

    print(DP[-1].max())

if __name__ == "__main__":
    main()
    pass

Submission status: Runtime Error

Solution code:
n = int(input())
dp = [[0]*3  for _ in range(n)] 
ABC = []
for _ in range(n):
    a,b,c = map(int,input().split())
    ABC.append([a,b,c])

def rec(flag,num):# flag は A=0,B=1,C=2を表す。 numは何番目かを表す。
    if dp[num][flag] != 0:
        return dp[num][flag]
    if num == 0:
        dp[num][flag] = ABC[num][flag]
        return dp[num][flag]
    else:
        res = 0
        if flag == 0:
            res = max(rec(1,num-1),rec(2,num-1))+ABC[num][flag]
        elif flag == 1:
            res = max(rec(0,num-1),rec(2,num-1))+ABC[num][flag]
        else:
            res = max(rec(1,num-1),rec(0,num-1))+ABC[num][flag]
        dp[num][flag] = res
        return dp[num][flag]

rec(0,n-1)
rec(1,n-1)
rec(2,n-1)

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())  #nは入力回数
num_list = [list(map(int, input().split())) for _ in range(n)]
dp_ini=0
dp=np.zeros((n+1,n))
for i in range(0,n):
  for j in range(3):
    for k in range(3):
      if(j==k):
        continue
      else:
        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+num_list[i][k])
print(int(max(dp[n][0],dp[n][1],dp[n][2])))

Submission status: Runtime Error

Solution code:
import numpy as np
#n,k=map(int,input().split())
n=int(input())
abc=[]
for _ in range(n):
      abc.append(list(map(int,input().split())))
dp=np.zeros(n+1)
# dp[i]:i日目までの最大。dp[0]=0。求めるのはdp[n]
dp[1]=max(abc[0])
op1=[i for i in range(3) if abc[0][i]!=dp[1]]
if len(op1)<2:
      op1=[0,1,2]
op2=[0,1,2]
for i in range(2,n+1):
      m=max([abc[i-1][j] for j in op1])
      m1=dp[i-1]+m
      op=[j for j in range(3) if abc[i-1][j]!=m]
      if len(op)<2:
            op=[0,1,2]
      opt=[j for j in range(3) if abc[i-1][j]!=max(abc[i-1])]
      if len(op)<2:
            opt=[0,1,2]
      m2=dp[i-2]+max(abc[i-1])+max([abc[i-2][j] for j in set(op2).intersection(set(opt))])
      dp[i]=max(m1,m2)
      op2=op1
      op1=op

print(int(dp[-1]))

Submission status: Runtime Error

Solution code:
import sys


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


def main():
    size = int(input())
    array = []
    dp = [0] * size
    for _ in range(size):
        z = (list(map(int, input().split())))
        newDp = [0] * size
        for i in range(3):
            for j in range(3):
                if j != i:
                    newDp[j] = max(newDp[j], dp[i] + z[j])
        dp = newDp
    print(max(dp[0],dp[1],dp[2]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def q3():
    def lcm(x, y):
        """ xとyの最小公倍数を求める """
        # import math
        import fractions
        return (x * y) // fractions.gcd(x, y)

    A, B = (int(i) for i in input().split())
    print(lcm(A, B))


if __name__ == '__main__':
    q3()

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
dp=[0]*(N+1)


for i in range(N):
    a,b,c = map(int,input().split())
    if i == 0:
        dp[i+1] = dp[i]+max(a,b,c)
        flg = [a,b,c].index(max([a,b,c]))
    else:
        if flg==0:
            dp[i+1] = dp[i] + max(b,c)
            flg = [a,b,c].index(max([b,c]))
        elif flg==1:
            dp[i+1] = dp[i] + max(a,c)
            flg = [a,b,c].index(max([a,c]))
        else:
            dp[i+1] = dp[i] + max(a,b)
            flg = [a,b,c].index(max([a,b]))

# print(dp)
print(dp[N])

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a=[input() for i in range(h)]
mod=10**9+7
d=[[0]*w for i in range(h)]
d[0][0]=1
for i in range(h):
    for j in range(w):
        if i+1<h and a[i+1][j]==".":
            d[i+1][j]+=d[i][j]
            d[i+1][j]%=mod
        if j+1<w and a[i][j+1]==".":
            d[i][j+1]+=d[i][j]
            d[i][j+1]%=mod
print(d[-1][-1])

Submission status: Runtime Error

Solution code:
def solve(a):
    dp = [[0]*3 for _ in range(len(a)+1)]
    for i in range(len(a)):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[i+1][j] = max(dp[i+1][j], a[i][j] + dp[i][k])
    return max(dp[-1])
  
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
print(solve(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
c=[0]*(n-1)
for _ in range(n-1):
    a,b,c=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]))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
 
N = int(input())
H = list(list(map(int,input().split())) for _ in range(N))
#sub problem: max cost from 0 to ith day
memo = {}
def rec(i, choice):
  if memo[(i, choice)]:
    return memo[(i,choice)]
  if i == len(H):
    return 0
  m = max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
  memo[(i, choice)] = m
  return m
print(max(rec(0, j) for j in range(3)))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000000)

N = int(input())
H = list(list(map(int,input().split())) for _ in range(N))
#sub problem: max cost from 0 to ith day
def rec(i, choice):
  if i == len(H):
    return 0
  return max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
print(max(rec(0, j) for j in range(3)))

Submission status: Runtime Error

Solution code:
N = int(input())
H = list(list(map(int,input().split())) for _ in range(N))
#sub problem: max cost from 0 to ith day
def rec(i, choice):
  if i == len(H):
    return 0
  return max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
print(max(rec(0, j) for j in range(3)))

Submission status: Runtime Error

Solution code:
N = int(input())
H = list(list(map(int,input().split())) for _ in range(N))
#sub problem: max cost from 0 to ith day
def rec(i, choice):
  if i == len(H):
    return 0
  return max((H[i][j] + rec(i+1,j) for j in range(3) if j != choice), default=0)
print(max((rec(0, j) for j in range(3)), default=0))

Submission status: Runtime Error

Solution code:
N = int(input())

H = list(list(map(int,input().split())) for _ in range(N))

#sub problem: max cost from 0 to ith day
def rec(i, choice):
  if i == len(H):
    return 0
  m = max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
  print(m)
  return m
print(max(rec(0, j) for j in range(3)))

Submission status: Runtime Error

Solution code:
N = int(input())

H = list(list(map(int,input().split())) for _ in range(N))

#sub problem: max cost from 0 to ith day
def rec(i, choice):
  if i == len(H):
    return 0
  return max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
print(max(rec(0, j) for j in range(3)))

Submission status: Runtime Error

Solution code:
N = int(input())

H = list(list(map(int,input().split())) for _ in range(N))

#sub problem: min cost from 0 to i
def rec(i, choice):
  if i == len(H):
    return 0
  return max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
print(max(rec(0, j) for j in range(3)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
total = []
dp = np.zeros((3,N), dtype = int)
for i in range(N):
  tmp = list(map(int,input().split()))
  if i == 0:
    dp[i][0] = tmp[0]
    dp[i][1] = tmp[1]
    dp[i][2] = tmp[2]
  else:
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + tmp[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + tmp[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + tmp[2]
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

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] = 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):
    for j in range(2):
        for k in range(2):
            if j!=k:
                dp[i+1][j]=max(dp[i+1][j],dp[i][k] + a[i+1][j])
            else:
                pass

print(max(dp[N-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] = 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):
    for j in range(2):
        for k in range(2):
            if j!=k:
                dp[i+1][j]=max(dp[i+1][j],dp[i][k] + a[i+1][j])
            else:
                pass

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

Submission status: Runtime Error

Solution code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[None]*3 for _ in range(n)]
dp[0] = abc[0]
K = [[1, 2], [0, 2], [0, 1]]
for i in range(1, n):
    abci = abc[i]
    for j in range(3):
        for k in K[j]:
            dp[i][j] = max(dp[i-1][k[0]]+abci[j], dp[i-1][k[1]]+abci[j])
print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**8)
n,k=map(int,input().split())
z=list(map(int,input().split()))
dp=[0 for i in range(len(z))]
vi=[0 for i in range(len(z))]
def dps(i,dp,vi):
    if(i<=0):
        return 0;
    if(vi[i]==1):
        return dp[i];
    
    vi[i]=1
    maxa=98778979878
    for j in range(1,min(i+1,k+1)):
        maxa=min((dps(i-j,dp,vi)+abs(z[i]-z[i-j])),maxa)
    dp[i]=maxa
    return dp[i];
print(dps(len(z)-1,dp,vi))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
ABC = [[int(x) for x in readline().split()] for _ in range(N)]

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

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

ans = max(dp[N])
print(ans)

Submission status: Runtime Error

Solution code:
n= int(input())
dp =[0]*3
for i in range(n):
    ndp=[0]*3
    c =list(map(int,input().split()))
    for j in range(n):
        for k in range(n):
            if j !=k:
                ndp[k] = max(ndp[k],dp[j]+c[k])
    dp = ndp
print(max(dp))

Submission status: Runtime Error

Solution code:
n= int(input())
dp =[0]*3
for i in range(n):
    ndp=[0]*3
    c =list(map(int,input().split()))
    for j in range(n):
        for k in range(n):
            if i !=j:
                ndp[k] = max(ndp[k],dp[j]+c[k])
    dp = ndp
print(max(dp))

Submission status: Runtime Error

Solution code:
N = int(input())
dp = [0,0,0]
for _ in range(N):
    a, b, c = map(int, input().split())
    ndp = [0,0,0]
    ndp[0] = max(dp[1], dp[2]) + a
    ndp[1] = max(dp[0], dp[2]) + b
    ndp[2] = max(dp[0], dp[1]) + c
    dp = ndp
return max(dp)

Submission status: Runtime Error

Solution code:
import sys
 
def main():
  N, W = map(int, input().split())
  w = [0]*N
  v = [0]*N
  for i in range(N):
          w[i], v[i] = map(int, sys.stdin.readline().split())
 
  #WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
 
 
  dp = [[0]*(N+1) for j in range(W+1)]
 
  for i in range(1, W+1):
          for j in range(1, N+1):
                  if i - w[j-1]>=0:
                  #if i - WV[j-1][0]>=0:
                          dp[i][j] = max(dp[i-w[j-1]][j-1]+v[j-1], dp[i][j-1])
                          #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                  else:
                          dp[i][j] = dp[i][j-1]
 
  print(dp[W][N])
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


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


def main():

    N = int(input())
    DATA = [list(map(int, input().split())) for i 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] + DATA[i][k])

    res = 0

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

    print(res)


if __name__ == '__main__':
    N = int(input())
    A = [int(x) for x in input().split()]
    main(N, A)

Submission status: Runtime Error

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


input = sys.stdin.readline


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

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

or 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(3):
    res = max(res, dp[N][v])

print(res)

Submission status: Runtime Error

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


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


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

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

or 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(3):
    res = max(res, dp[N][v])

print(res)

Submission status: Runtime Error

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


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


N = int(input())
DATA = [map(int, input().split()) for i 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] + DATA[i][k])

    res = 0

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

    print(res)

Submission status: Runtime Error

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

input = sys.stdin.readline

def main(N, DATA):
    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] + DATA[i][k])

    res = 0

    for v in range(3):
        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(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] + DATA[i][k])

    res = 0

    for v in range(3):
        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


input = sys.stdin.readline


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 = [list(map(int, input().split())) for i in range(N)]
    r = main(N, DATA)
    print(r)