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:
import sys
input = sys.stdin.readline

N, W = map(int, input().split())

w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

def func(N, W):
    dp = [0] * (W+1)
    for i in range(N):
        for j in range(W, w[i]-1, -1):
            a = dp[j-w[i]] + v[i]
            if dp[j] < a:
                dp[j] = a
    return dp[W]

print(func(N, W))

Submission status: Runtime Error

Solution code:
n=int(input())
lst=[]
h=[1000000000000]*(n+1)
for i in range(n):
  lst.append(list(map(int,input().split())))  
for i in range(1,n+1):
  for j in range(3):
    for k in range(3):
      if j==k:
        if h[i]>h[i-1][j]+lst[i-1][k]:
          h[i]=h[i-1][j]+lst[i-1][k]
print(h[n])

Submission status: Runtime Error

Solution code:
N = int(input())

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

for i in range(N):
    v1, v2, v3 = map(int, input().split())
    vals[i][0] = v1
    vals[i][1] = v2
    vals[i][2] = v3

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

dp[0][0] = vals[0][0]
dp[0][1] = vals[0][1]
dp[0][2] = vals[0][2]

for i in range(1, N):
    for activity in range(3):
        for pastActivity in range(3):
            if activity == pastActivity: continue
            
            dp[i][activity] = max(dp[i][activity],
                                  dp[i-1][pastActivity] + vals[i][activity])

print(max(dp[-1]))

Submission status: Runtime Error

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

dp = [0,0,0]*N
dp[0] = li[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] = dp[i][k] + li[i+1][j]
print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
def MAXI(a):
    m=max(a)
    for i in range(3):
        if a[i]==m:
            id=i
    return m,id



tot=0
N=int(input())
i=0
while i<N:
    
    if i==0:
        x=[int(a) for a in input().split()]
        m,id=MAXI(x)
        tot+=m
        i=i+1
    else:
        x=[int(a) for a in input().split()]
        y=[int(a) for a in input().split()]
        i=i+2
        MAX=0
        for j in range(3):
            if j!=id:
                for k in range(3):
                    if k!=j:
                        s=x[j]+y[k]
                        if s>MAX:
                            MAX=s
                            id1=k
                        
        tot+=MAX
        id=id1
                            
        
print(tot)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
const long long INF = 1e9;

int main()
{
  int n; cin >> n;
  vector<vector<int>> happy(n, vector<int>(3));
  for(int i = 0; i < n; i++){
    cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
  }
 
  vector<vector<int>> dp(n+1, vector<int>(3));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j == k) continue;
        dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happy[i][j]);
      }
    }
  }

  cout << max_3(dp[n][0], dp[n][1], dp[n][2]) << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
A = B = C = 0

for i in range(N):
  a,b,c = map(int,input())
  A,B,C = max(B + a,C+a),max(A+b,C+b),max(A+c,B+c)
 
print(max(A,B,C))

Submission status: Runtime Error

Solution code:
print(vacation_planning(a,b,c))

Submission status: Runtime Error

Solution code:
mem={}
def dp_sol(vac,n,act):
    key = str(n)+":"+str(act)
    if key in mem.keys():
        return mem[key]
    if n==0:
        return vac[n][act]
    elif n<0:
        return 0
    else:
        if act==-1:
            mem[key] = max(vac[n][0]+max(dp_sol(vac,n-1,1),dp_sol(vac,n-1,2)) , vac[n][1]+max(dp_sol(vac,n-1,0),dp_sol(vac,n-1,2))
                        , vac[n][2]+max(dp_sol(vac,n-1,0),dp_sol(vac,n-1,1)))
        elif act==0:
            mem[key] = vac[n][0] + max(dp_sol(vac,n-1,1),dp_sol(vac,n-1,2))
        elif act==1:
            mem[key] = vac[n][1]+max(dp_sol(vac,n-1,0),dp_sol(vac,n-1,2))
        else:
            mem[key] = vac[n][2]+max(dp_sol(vac,n-1,0),dp_sol(vac,n-1,1))
        return mem[key]
n=int(input())
vac=[]
for i in range(n):
    vac.append([])
    vac[i] = [int(ele) for ele in input().split()]
if n==1:
    print(max(vac[0][0],vac[0][1],vac[0][2]))
else:
    print(dp_sol(vac,n-1,-1))

Submission status: Runtime Error

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

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

dpa = a[0]+[0]*(n-1)
dpb = b[0]+[0]*(n-1)
dpc = c[0]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max( dpb[i-1]+a[i], dpc[i-1]+a[i])
    dpb[i] = max( dpc[i-1]+b[i], dpa[i-1]+b[i])
    dpa[i] = max( dpa[i-1]+c[i], dpb[i-1]+c[i])

print(max(dpa[-1], dpb[-1], dpc[-1]))

Submission status: Runtime Error

Solution code:
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 for i in range(N)]for j 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]=[max(dp[i-1][1]+A[i],dp[i-1][2]+A[i]),max(dp[i-1][0]+B[i],dp[i-1][2]+B[i]),max(dp[i-1][0]+C[i],dp[i-1][1]+C[i])]
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=[]
for i in range(N):
  a,b,c=map(int,input().split())
  A.append(a)
  B.append(b)
  C.append(c)
dp=[[0 for i in range(N)]for j 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]=[max(dp[i-1][1]+A[i],dp[i-1][2]+A[i]),max(dp[i-1][0]+B[i],dp[i-1][2]+B[i]),max(dp[i-1][0]+C[i],dp[i-1][1]+C[i])]
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

Submission status: Runtime Error

Solution code:
n= int(input())
ABC = [[0]*3]*n
for i in range(n):
  ABC[i][0],ABC[i][1],ABC[i][2] = map(int, input().split())

dp = [[0]*3]*n
dp[0] = ABC[0]

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

Submission status: Runtime Error

Solution code:
import os, sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
 
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7

def n(): return int(sys.stdin.readline())
def li(): return list(map(int, sys.stdin.readline().split()))
def bulk_li(): return list(map(lambda s: list(map(int, s.split())), sys.stdin.readlines()))

N = n()
abc = bulk_li()  # [[a_i, b_i, c_i]...]

dp = np.zeros((N, 3), dtype='int32')  # [[Ai, Bi, Ci]...]
# fl = np.zeros((N, 3), dtype='int32')  # [[fl_ai, fl_bi, fl_ci]...]
choice = np.ones((3,3)) - np.diag([1]*3)

S = [
    [0, 1],
    [0, 2],
    [1, 0],
    [1, 2],
    [2, 0],
    [2, 1],
]

T = [
    [[1, 1], [2, 2]],
    [[0, 0], [2, 2]],
    [[0, 0], [1, 1]]
]

for j in range(3):
    dp[0][j] = abc[0][j]
    dp[1][j] = max(abc[0]) + abc[1][j]

for i in range(N-2):
    for j in range(3):
        pattern = S + T[j]
        next = [dp[i][j] + abc[i+1][j_] for j, j_ in pattern]
        # print(i, j, next)
        dp[i+2][j] = max(next) + abc[i+2][j]

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


"""

"""

Submission status: Runtime Error

Solution code:
n = int(raw_input())


class Day(object):
	def __init__(self,i):
		self.i = i
		self.a,self.b,self.c = map(int,raw_input().split(' '))

	def update_totals(self):
		if self.i==0:
			return
		previous = days[self.i-1]
		self.a += max(previous.b,previous.c)
		self.b += max(previous.a,previous.c)
		self.c += max(previous.b,previous.c)

days = [Day(i) for i in range(n)]
for day in days:
	day.update_totals()

print max(days[-1].a,days[-1].b,days[1].c)

Submission status: Runtime Error

Solution code:
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

#dp[i][w]
def main():
	n,w = map(int,input().split())
	wv = [list(map(int,input().split())) for i in range(n)]
	dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
	for i in range(1,n+1):
		cw = wv[i-1][0]
		cv = wv[i-1][1]
		for j in range(w+1):
			dp[i][j] = max(dp[i-1][j],dp[i-1][j-cw] + cv) if j-cw >= 0 else dp[i-1][j]
	print(dp[-1][-1])

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Submission status: Runtime Error

Solution code:
N = int(input())
dp = [[0]*(N+1) for _ in range(3)]
happy = [[0]*N for _ in range(3)]

for i in range(N):
    a, b, c = [int(s) for s in input().split()]
    happy[i][0] = a
    happy[i][1] = b
    happy[i][2] = c

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][j] + happy[i][k])

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

Submission status: Runtime Error

Solution code:
N = int(input())
for i in range(N):
        a,b,c = map(int,input().split())
        if i == 0:
                preA = a
                preB = b
                preC = c
        else:
                A = max(preB + a, preC + a)
                B = max(preA + b, preC + b)
                C = max(preA + c, preB + c)
                preA = A
                preB = B
                preC = C
print(max(A, B, C))

Submission status: Runtime Error

Solution code:
N, W = map(int, input().split())

DP = [-1] * (W+1)
DP[W] = 0

def maxv(i, v):
    if i >= 0:
        if v > DP[i]:
            DP[i] = v

for w, v in (map(int, input().split()) for _ in range(N)):
    for i in range(1, W+1):
        if DP[i] >= 0:
            maxv(i-w, DP[i]+v)
            maxv(0, DP[i-w])

print(DP[0])

Submission status: Runtime Error

Solution code:
from functools import lru_cache

N = int(input())
ABC = [list(map(int, input().split(" "))) for _ in range(N)]

# l = [[0 for _ in range(3)] for _ in range(N+10)]
@lru_cache(maxsize=None)
def dp(i, use):
    if i == -1:
        return 0
    max_num = 0
    for k in range(3):
        if k == use:
            continue
        max_num = max(max_num, dp(i-1, k)+ABC[i][use])
    return max_num

print(max(dp(N-1, m) for m in range(3)))

Submission status: Runtime Error

Solution code:
def func(i, j):
	if i >= N:
		return 0
	if dp[i][j] != -1:
		return dp[i][j]
	if j == 0:
		dp[i][j] = val[i][j] + max(func(i+1, 1), func(i+1, 2))
		return dp[i][j]
	if j == 1:
		dp[i][j] = val[i][j] + max(func(i+1, 0), func(i+1, 2))
		return dp[i][j]
	if j == 2:
		dp[i][j] = val[i][j] + max(func(i+1, 0), func(i+1, 1))
		return dp[i][j]

N = int(input())
dp = []
val = []

for i in range(N):
	x = []
	y = []
	for j in range(3):
		x.append(-1)
		y.append(0)
	dp.append(x)
	val.append(y)

for i in range(N):
	val[i][0], val[i][1], val[i][2] = input().split()
	val[i][0] = int(val[i][0])
	val[i][1] = int(val[i][1])
	val[i][2] = int(val[i][2])

func(0, 0)
func(0, 1)
func(0, 2)

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

Submission status: Runtime Error

Solution code:
n = int(input())
dp = [[0]*n for i in range(n)]
for i in range(n):
    l = list(map(int , input().split()))
    if i == 0:
        dp[0][0]=l[0]
        dp[0][0]=l[1]
        dp[0][0]=l[2]
    else:
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+l[0]
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+l[1]
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+l[2]
print(max(dp[-1][0], dp[-1][1], dp[-1][2]))

Submission status: Runtime Error

Solution code:
n = int(input())
dp=[0 for i in range(3)]
for tt in range(n):
  l=list(map(int,input().split()))
  if tt==0:
    dp[0],dp[1],dp[2]=l[0],l[1],l[2]
  else:
    dp[0]=max(dp[0]+l[1],dp[0]+l[2]))
    dp[1]=max(dp[1]+l[0],dp[1]+l[2]))
    dp[2]=max(dp[2]+l[0],dp[2]+l[1]))
  # print("this is dp "+str(dp))
print(max(dp))

Submission status: Runtime Error

Solution code:
n=int(input())
def recuur(g,x,y,z):
     global n

     if z==n-1:
        return y
     if x==1:
         return y+max(recuur(g,2,g[z+1][2],z+1),recuur(g,0,g[z+1][0],z+1))
     if x==2:
         return y+max(recuur(g,1,g[z+1][1],z+1),recuur(g,0,g[z+1][0],z+1))
     if x==0:
         return y+max(recuur(g,2,g[z+1][2],z+1),recuur(g,1,g[z+1][1],z+1))

g=[[0,0,0] for _ in range(n)]
for u in range(n):
    a,b,c=map(int,input().split())
    g[u][1],g[u][2],g[u][0]=b,c,a
dp=[ [0,0] for _ in range(n)]
dp[0]=[max(g[0]),g[0].index(max(g[0]))]
print(recuur(g,dp[0][1],dp[0][0],0))

Submission status: Runtime Error

Solution code:
dp = [[0]*3 for i in range(n)]
dp[0] = abc[0]

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

Submission status: Runtime Error

Solution code:
n = int(input())

data = np.zeros((n, 3), dtype=np.int64)

for i in range(n):

  data[i] = list(map(int, input().split()))

dp = np.zeros((n+1, 3), dtype=np.int64)

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i+1][j] = np.maximum(dp[i][k] + data[i][j], dp[i+1][j])

print(np.max(dp[n]))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
ABC = [list(map(int,input().split())) for i in range(N)]

dp = [0]*(N+1)

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

print(max(dp[N]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=list([*map(int,input().split())] for i in range(n))
ans=[[0,0,0] for i in range(n+1)]
for i in range(n):
    ans[i+1][0]=max(ans[i][1]+l[i][0],ans[i][2]+l[i][0])
    ans[i+1][1]=max(ans[i][2]+l[i][1],ans[i][0]+l[i][1])
    ans[i+1][2]=max(ans[i][0]+l[i][2],ans[i][1]+l[i][2])
print(max(ans[-1]))

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l=[[*map(raw_int,input().split())] for i in range(n)]
ans=0
prev=""
for i in range(n):
    a,b,c=l[i]
    if(a>b and a>c):
        if(prev!='a'):
            ans+=a
            prev='a'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][0]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+a)
                prev='a'
    elif(b>a and b>c):
        if(prev!='b'):
            prev='b'
            ans+=b
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][1]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+b)
                prev='b'
    elif(c>a and c>b):
        if(prev!='c'):
            ans+=c
            prev='c'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][2]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+c)
                prev='c'
    else:
        ans+=max(l[i])
        z=max(l[i])
        if(z==a and prev!='a'):
            prev='a'
        elif(z==b and prev!='b'):
            prev='b'
        else:
            prev='c'
print ansn=int(raw_input())
l=[[*map(raw_int,input().split())] for i in range(n)]
ans=0
prev=""
for i in range(n):
    a,b,c=l[i]
    if(a>b and a>c):
        if(prev!='a'):
            ans+=a
            prev='a'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][0]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+a)
                prev='a'
    elif(b>a and b>c):
        if(prev!='b'):
            prev='b'
            ans+=b
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][1]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+b)
                prev='b'
    elif(c>a and c>b):
        if(prev!='c'):
            ans+=c
            prev='c'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][2]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+c)
                prev='c'
    else:
        ans+=max(l[i])
        z=max(l[i])
        if(z==a and prev!='a'):
            prev='a'
        elif(z==b and prev!='b'):
            prev='b'
        else:
            prev='c'
print ans

Submission status: Runtime Error

Solution code:
n=int(input())
l=[[*map(int,input().split())] for i in range(n)]
ans=0
prev=""
for i in range(n):
    a,b,c=l[i]
    if(a>b and a>c):
        if(prev!='a'):
            ans+=a
            prev='a'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][0]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+a)
                prev='a'
    elif(b>a and b>c):
        if(prev!='b'):
            prev='b'
            ans+=b
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][1]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+b)
                prev='b'
    elif(c>a and c>b):
        if(prev!='c'):
            ans+=c
            prev='c'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][2]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+c)
                prev='c'
    else:
        ans+=max(l[i])
        z=max(l[i])
        if(z==a and prev!='a'):
            prev='a'
        elif(z==b and prev!='b'):
            prev='b'
        else:
            prev='c'
    #print(ans,prev)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[[*map(int,input().split())] for i in range(n)]
ans=0
prev=""
for i in range(n):
    a,b,c=l[i]
    if(a>b and a>c):
        if(prev!='a'):
            ans+=a
            prev='a'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][0]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+a)
                prev='a'
    elif(b>a and b>c):
        if(prev!='b'):
            prev='b'
            ans+=b
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][1]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+b)
                prev='b'
    elif(c>a and c>b):
        if(prev!='c'):
            ans+=c
            prev='c'
        else:
            x=[a,b,c]
            x.sort()
            y=l[i-1].copy()
            y.sort()
            if(l[i-1][2]+x[1]>=y[1]+x[-1]):
                ans+=x[1]
                if(x[1]==a):
                    prev='a'
                elif(x[1]==b):
                    prev='b'
                else:
                    prev='c'
            else:
                ans-=y[-1]
                ans+=(y[1]+c)
                prev='c'
    else:
        ans+=max(l[i])
        z=max(l[i])
        if(z==a):
            prev='a'
        elif(z==b):
            prev='b'
        else:
            prev='c'
    #print(ans,prev)
print(ans)

Submission status: Runtime Error

Solution code:

import sys

intMaxValue = sys.maxsize


def problem():
    N = int(input.split())
    activityList = []
    for i in range(N):
      row = list(map(int, input().split()))
      activityList.append(row)

    print(algorithm(N,activityList))

def algorithm(N, activityList):
  dp = [[0, 0, 0] for i in range(N+ 1)]

  for index in range(1, N + 1):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        if dp[index][j] < dp[index - 1][k] + activityList[index-1][j]:
          dp[index][j] = dp[index - 1][k] + activityList[index-1][j]
      
  return max(dp[N])


problem()

Submission status: Runtime Error

Solution code:
N = int(input())
sel = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * N for _ in range(N+1)]

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

print(max(dp[N]))

Submission status: Runtime Error

Solution code:
def c():
    N = int(input())
    abc = [list(map(int, input().split())) for _ in range(N)]
    dp = [[0] * N for _ in range(3)]
    for i in range(N):
        dp[0][i] = max(dp[1][i - 1] + abc[i][0], dp[2][i - 1] + abc[i][0])
        dp[1][i] = max(dp[0][i - 1] + abc[i][1], dp[2][i - 1] + abc[i][1])
        dp[2][i] = max(dp[0][i - 1] + abc[i][2], dp[1][i - 1] + abc[i][2])
    return max(dp[:][i])


if __name__ == '__main__':
    ans = c()
    print(ans)

Submission status: Runtime Error

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

import numpy as np

N = int(input())

dp = np.zeros((N+1, 3), dtype=int)
arr = np.zeros((N, 3), dtype=int)
for i in range(N):
  arr[i] = list(map(int, input().split()))

# dp roop
for i in range(N):
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i+1, k] = np.maximum(dp[i+1, k], dp[i, j] + arr[i, k])
print(max(dp[N]))import sys
input = sys.stdin.readline

import numpy as np

N = int(input())

dp = np.zeros((N+1, 3), dtype=int)
arr = np.zeros((N, 3), dtype=int)
for i in range(N):
  arr[i] = list(map(int, input().split()))

# dp roop
for i in range(N):
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i+1, k] = np.maximum(dp[i+1, k], dp[i, j] + arr[i, k])
print(max(dp[N]))

Submission status: Runtime Error

Solution code:
N = int(input())
dp = [[0 for _ in range(N+1)] for i in range(3)]

for i in range(1,N+1):
  ai,bi,ci = map(int,input().split())
  
  dp[i][0] = ai + max(dp[i-1][1],dp[i-1][2])
  dp[i][1] = bi + max(dp[i-1][0],dp[i-1][2])
  dp[i][2] = ci + max(dp[i-1][1],dp[i-1][0])
  
print(max(dp[N]))

Submission status: Runtime Error

Solution code:
N = int(input())
M = []
for _ in range(N):
    M.append(list(map(int, input().split())))
h = [0]*N
c = 0
for i,m in enumerate(M):
    if i==0:
        h[i] = max(m)
        c = m.index(h[i])
    else:
        h[i] = h[i-1]+max(map(lambda x: 0 if m.index(x)==c else x, m))
        c = m.index(h[i]-h[i-1])
print(h[-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

dp = [[-1]*3 for i in range(N)]
import sys
sys.setrecursionlimit(10**10)
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))

Submission status: Runtime Error

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

dp = [[-1]*3 for i in range(N)]
import sys
sys.setrecursionlimit(10**5)
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))

Submission status: Runtime Error

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

dp = [[-1]*3 for i in range(N)]
def dfs(i,j):
    if i == N:
        return 0
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j==0:
            dp[i][j] = max(dfs(i+1,1)+abc[i][1], dfs(i+1,2)+abc[i][2])
        elif j==1:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,2)+abc[i][2])
        else:
            dp[i][j] = max(dfs(i+1,0)+abc[i][0], dfs(i+1,1)+abc[i][1])
        return dp[i][j]
print(max(dfs(0,0), dfs(0,1), dfs(0,2)))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
typedef long long lint;
const lint MOD = 10e9;
typedef vector<int> vint;
typedef pair<int, int> pint;
template <class T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    int a[N + 1], b[N + 1], c[N + 1];
    rep(i, 1, N + 1) { cin >> a[i] >> b[i] >> c[i]; }
    int dp[N + 10][3];
    rep(i, 3) { dp[0][i] = 0; }
    rep(i, 1, N + 1) {
        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][1] + c[i], dp[i - 1][0] + c[i]);
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << "\n";
}

Submission status: Runtime Error

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

dp = [[0 if j != 0 else actions[i][j] for i in range(3)] for j in range(num)]
for i in range(num) if i != 0:
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + actions[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + actions[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + actions[i][2]

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