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:
N = int(input())
L = []

for i in range(N):
  l = list(map(int,input().split()))
  L.append(l)
  
dp = [[0,0,0] for i in range(N + 1)]
dp[1] = [L[1][0],L[1][1],L[1][2]]

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

Submission status: Runtime Error

Solution code:
"""
NTC here
"""
import sys
input= sys.stdin.readline
# import t  hreading
# setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())
def lin(): return list(map(int, input().split()))

# range = xrange
# input = raw_input

def main():
    n, k= lin()
    h=lin()
    ans=[0]*(n)
    for i in range(n-2,-1,-1):
        ans[i]=min(
            [abs(h[i]-h[j+i+1])+ans[i+j+1] for j in range(min(n-i-1,k))]
            )
    print(ans[0])
        



                









        
main()
#threading.Thread(target=main).start()

Submission status: Runtime Error

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

def f(cur_day=0, cur_sum=0, prev_activity=None):

    print(cur_day, [data[cur_day][k] if k!=prev_activity else -1 for k in range(3)])
    if cur_day == n-1:
        return cur_sum + max([data[n-1][k] if k!=prev_activity else -1 for k in range(3)])
    tmp = max([f(cur_day + 1, cur_sum=cur_sum + data[cur_day][k], prev_activity=k)
               if k!=prev_activity else -1 for k in range(3)])

    return tmp

if __name__ == "__main__":
    n = map(int, input())
    data = []
    for j in range(n):
        data.append(list(map(int, input().split(" "))))
    points = f()
    print(points)

Submission status: Runtime Error

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

def f(cur_day=0, cur_sum=0, prev_activity=None):

    print(cur_day, [data[cur_day][k] if k!=prev_activity else -1 for k in range(3)])
    if cur_day == n-1:
        return cur_sum + max([data[n-1][k] if k!=prev_activity else -1 for k in range(3)])
    tmp = max([f(cur_day + 1, cur_sum=cur_sum + data[cur_day][k], prev_activity=k)
               if k!=prev_activity else -1 for k in range(3)])

    return tmp

if __name__ == "__main__":
    n = map(int, input().split())
    data = []
    for j in range(n):
        data.append(list(map(int, input().split(" "))))
    points = f()
    print(points)

Submission status: Runtime Error

Solution code:
## tasks https://atcoder.jp/contests/dp/tasks
## TODO

def solution():
    # result array for calculation for optimal cost for every stone
    res = [[-1 for x in range(3)] for y in range(n)]
    res[0] = a[0]
    for i in range(1,n):
        # going through the all days
        for j in range(3):
            # calucaltion for every possible actions, but skipping the same activity
            # picked current activity is j, let us get options from non j and get max of them
            # it will be a cost for j
            # do it for every

            #searching for best previous happines
            bph = -1
            for o in range(3):
                #skipping the same activity
                if o==j:
                    continue
                bph = max(bph, res[i-1][o])
            #print("res = {} a = {}".format(res, a))
            #print("i={} j={}".format(i, j))
            res[i][j] = max(res[i][j], bph + a[i][j])

    return max(res[-1][0],res[-1][1],res[-1][2])


if __name__ == "__main__":
    n = int(input())

    a = [[None for x in range(3)] for y in range(n)]

    for i in range(n):
        row = list(map(int, raw_input().split(" ")))
        for j in range(3):
            a[i][j] = row[j]

    #print("n = {} a = {}".format(n, a))
    if n == 1:
        print max(a[0][0],a[0][1],a[0][2])
    else:
        print(solution())

Submission status: Runtime Error

Solution code:
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll dp[maxn][5];

int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    repd(i,2,n)
    {
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

Submission status: Runtime Error

Solution code:
def abcCalc(abc, dp):
    return [abc[0] + max(dp[1], dp[2]), abc[1] + max(dp[0], dp[2]), abc[2] + max(dp[0], dp[1])]

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

if len(abcList) == 1:
    print(max(abcList[0][0], abcList[0][1], abcList[0][2]))
    return

dp.append(abcCalc(abcList[1], dp[0]))

for i in range(2, N):
    dp.append(abcCalc(abcList[i], dp[i-1]))
print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
def abc(abc, dp):
    return [abc[0] + max(dp[1], dp[2]),
            abc[1] + max(dp[0], dp[2]),
            abc[2] + max(dp[0], dp[1])]

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

if len(abcList) == 1:
    print(max(abcList[0][0], abcList[0][1], abcList[0][2]))
    return

dp.append(abc(abcList[1], dp[0]))

for i in range(2, N):
    dp.append(abc(abcList[i], dp[i-1]))
print(max(dp[-1]))

Submission status: Runtime Error

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

if len(abcList) == 1:
    print(max(abcList[0][0], abcList[0][1], abcList[0][2]))
    return

dp.append(abc(abcList[1], dp[0]))

for i in range(2, N):
    dp.append(abc(abcList[i], dp[i-1]))
print(max(dp[-1]))

Submission status: Runtime Error

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

if len(abcList) == 1:
    print(max(abcList[0][0], abcList[0][1], abcList[0][2]))
    return

# dp=1
dp.append(abc(abcList[1], dp[0]))

for i in range(2, N):
    dp.append(abc(abcList[i], dp[i-1]))
print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
import cmath
import numpy
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    N=int(input())
    dp=[0, 0, 0]
    for line in sys.stdin.readlines():
        a,b,c=map(int, line.split())
        ndp=[0, 0, 0]
        ndp[0]=max(dp[1], dp[2])+a
        ndp[1]=max(dp[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp
    print(max(dp))

main()

Submission status: Runtime Error

Solution code:
import cmath
import numpy as np
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    N=int(input())
    dp=[0, 0, 0]
    for line in sys.stdin.readlines():
        a,b,c=map(int, line.split())
        ndp=[0, 0, 0]
        ndp[0]=max(dp[1], dp[2])+a
        ndp[1]=max(dp[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp
    print(max(dp))

main()

Submission status: Runtime Error

Solution code:
import cmath
import numpy as np
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    N=int(input())
    dp=[0, 0, 0]
    for line in sys.stdin.readlines():
        a,b,c=map(int, line.split())
        ndp=[0, 0, 0]
        ndp[0]=max(dp[1], dp[2])+a
        ndp[1]=max(dp[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp[:]
    print(max(dp))

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import cmath
import numpy as np
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    N=int(input())
    dp=[0, 0, 0]
    for line in sys.stdin.readlines():
        a,b,c=map(int, line.split())
        ndp=[0, 0, 0]
        ndp[0]=max(dp[1], dp[2])+a
        ndp[1]=max(dp[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp
    print(max(dp))

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import cmath
import numpy as np
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7

def main():
    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[2], dp[0])+b
        ndp[2]=max(dp[0], dp[1])+c
        dp=ndp
    print(max(dp))
        
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
happy = []
result = [[0 for i in range(3)] for j in range(N)]

for i in range(3):
    t = list( map( int, input().split() ) )
    happy.append(t)

for i in range(3):
    result[0][i] = happy[0][i] 

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
abc = [[input().split(" ")] for i in range(N)]
dp = [[-1 for i in range(3)] for i in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]
def A(day,abc):
	if day != 0:
		if abc == "a":
			dp[day][0] = max(dp[day-1][1] + abc[day][0],dp[day-1][2] + abc[day][0])
            return dp[day][0]
		elif abc == "b":
			dp[day][1] = max(dp[day-1][2] + abc[day][0],dp[day-1][0] + abc[day][0])
            return dp[day][1]
		else:
			dp[day][2] = max(dp[day-1][1] + abc[day][0],dp[day-1][0] + abc[day][0])
            return dp[day][2]
answer = [A(N,"a"),A(N,"b"),A(N,"c")]
print(max(answer))

Submission status: Runtime Error

Solution code:
memo = {}

def solve(i, last_option):
	global a, b, c
	if (i, last_option) not in memo:
		if i == len(a):
			result = 0
		elif i == 0:
			result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
		else:
			if last_option == 1:
				result = max(b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
			elif last_option == 2:
				result = max(a[i] + solve(i + 1, 1), c[i] + solve(i + 1, 3))
			else:
				result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2))
		memo[(i, last_option)] = result
		return result
	else:
		return memo[(i, last_option)]

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

Submission status: Runtime Error

Solution code:
memo = {}

def solve(a, b, c, i, last_option):
	if (i, last_option) not in memo:
		if i == len(a):
			result = 0
		elif i == 0:
			result = max(a[i] + solve(a, b, c, i + 1, 1), b[i] + solve(a, b, c, i + 1, 2), c[i] + solve(a, b, c, i + 1, 3))
		else:
			if last_option == 1:
				result = max(b[i] + solve(a, b, c, i + 1, 2), c[i] + solve(a, b, c, i + 1, 3))
			elif last_option == 2:
				result = max(a[i] + solve(a, b, c, i + 1, 1), c[i] + solve(a, b, c, i + 1, 3))
			else:
				result = max(a[i] + solve(a, b, c, i + 1, 1), b[i] + solve(a, b, c, i + 1, 2))
		memo[(i, last_option)] = result
		return result
	else:
		return memo[(i, last_option)]

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

Submission status: Runtime Error

Solution code:
n = int(input())
a,b,c = [],[],[]
for i in range(n):
    line = input()
    line = line.strip("\n").split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))
    c.append(int(line[2]))

def helper(i, prev=None, memo={}):
    if (i,prev) in memo: return memo[(i,prev)]

    if i >= n: return 0

    happ1 = 0 if prev == 'a' else a[i] + helper(i+1, 'a', memo)
    happ2 = 0 if prev == 'b' else b[i] + helper(i+1, 'b', memo)
    happ3 = 0 if prev == 'c' else c[i] + helper(i+1, 'c', memo)

    memo[(i,prev)] = max(happ1, happ2, happ3)
    return memo[(i, prev)]

print(helper(0))

Submission status: Runtime Error

Solution code:
n = int(input())
a,b,c = [],[],[]
for i in range(n):
    line = input()
    line = line.strip("\n").split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))
    c.append(int(line[2]))

def helper(i, prev=None, memo={}):

    if (i,prev) in memo: return memo[(i,prev)]

    if i >= n:
        return 0

    happ1, happ2, happ3 = 0,0,0
    if prev != 'a':
        happ1 = a[i] + helper(i+1, 'a', memo)
    if prev != 'b':
        happ2 = b[i] + helper(i+1, 'b', memo)
    if prev != 'c':
        happ3 = c[i] + helper(i+1, 'c', memo)

    ret = max(happ1, happ2, happ3)
    memo[(i,prev)] = ret
    return ret

print(helper(0))

Submission status: Runtime Error

Solution code:
n = int(input())
a,b,c = [],[],[]
for i in range(n):
    line = input()
    line = line.strip("\n").split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))
    c.append(int(line[2]))

def helper(i, prev=None, memo={}):

    if (i,prev) in memo: return memo[(i,prev)]

    if i == n:
        return 0

    happ1, happ2, happ3 = 0,0,0
    if prev != 'a':
        happ1 = a[i] + helper(i+1, 'a', memo)
    if prev != 'b':
        happ2 = b[i] + helper(i+1, 'b', memo)
    if prev != 'c':
        happ3 = c[i] + helper(i+1, 'c', memo)

    ret = max(happ1, happ2, happ3)
    memo[(i,prev)] = ret
    return ret

print(helper(0))

Submission status: Runtime Error

Solution code:
n = int(input())
a,b,c = [],[],[]
for i in range(n):
    line = input()
    line = line.strip("\n").split(" ")
    a.append(int(line[0]))
    b.append(int(line[1]))
    c.append(int(line[2]))

memo = {}
def helper(i, prev=None, memo={}):

    if (i,prev) in memo: return memo[(i,prev)]

    if i == n:
        return 0

    happ1, happ2, happ3 = 0,0,0
    if prev != 'a':
        happ1 = a[i] + helper(i+1, 'a', memo)
    if prev != 'b':
        happ2 = b[i] + helper(i+1, 'b', memo)
    if prev != 'c':
        happ3 = c[i] + helper(i+1, 'c', memo)

    ret = max(happ1, happ2, happ3)
    memo[(i,prev)] = ret
    return ret

print(str(helper(0)))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    dp = [0]*N
    array = []
    sum = 0
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)
    num = [[0,0,0] for z in range(N)]
    dp[0] = max(array[0][n] for n in range(3))
    for m in range(3):
        if dp[0] == array[0][m]:
            num[0][m] = 1
    
    
    for z in range(3):
        if num[0][z] == 1:
            dp[1] = max(dp[1],max(array[1][1],array[1][2])+dp[0])
            num[1][z] = 1
    

    for j in range(2,N):
        dpj = []
        for z in range(3):
            if 1 == num[j-1][z]:
                num[j][z] = 1
                dpj.append(max(array[j][1],array[j][2])+dp[j-1])
        dp[j] = max(dpj)
    
    print(dp[-1])
    
main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    dp = [0]*N
    array = []
    sum = 0
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)
    num = [[0,0,0] for z in range(N)]
    dp[0] = max(array[0][n] for n in range(3))
    for m in range(3):
        if dp[0] == array[0][m]:
            num[0][m] = 1
    
    
    for z in range(3):
        if num[0][z] == 1:
            dp[1] = max(dp[1],max(array[1][1],array[1][2])+dp[0])
            num[1][z] = 1
    
    print(num)
    for j in range(2,N):
        dpj = []
        for z in range(3):
            if 1 == num[j-1][z]:
                num[j][z] = 1
                dpj.append(max(array[j][1],array[j][2])+dp[j-1])
        dp[j] = max(dpj)
    
    print(dp[-1])
    
main()

Submission status: Runtime Error

Solution code:
dp=[[-1 for j in range(3)]for i in range(999999)]
def solve(l,n,i,col):

    if i>=n:
        return 0
    if dp[i][col]!=-1:return dp[i][col]

    mx=-1
    for j in range(3):
        if j!=col:
            mx=max(mx,l[i][col]+solve(l,n,i+1,j))
    dp[i][col]=mx
    return mx




def main():
    
    n=int(input())
    l=[[0 for i in range(3)]for j in range(n)]
    for i in range(n):
        l[i][0],l[i][1],l[i][2]=map(int,input().split())
    print(max(solve(l,n,0,0),solve(l,n,0,1),solve(l,n,0,2)))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main_C1():

  N = int(input())
  a = [[int(item) for item in line.split()] for line in input()]
  
  dp = [[0, 0, 0] for i in range(N+1)]

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

if __name__ == "__main__":
  main_C1()
  # print(list(input_gen()))

Submission status: Runtime Error

Solution code:
import numpy as np
# dp[i][j]: i+1日目に活動jをしたときのi+1日目までの幸福度の最大値
N = int(input())
abc = []
for i in range(N):
    abc.append(list(map(int, input().split())))
dp = np.zeros(shape=(N, 3), dtype=int)
dp[0, :] = abc[0]
for i in range(N-1):
    dp[i+1, 0] = max(dp[i+1, 0], dp[i, 1] + abc[i+1][0], dp[i, 2] + abc[i+1][0])
    dp[i+1, 1] = max(dp[i+1, 1], dp[i, 0] + abc[i+1][1], dp[i, 2] + abc[i+1][1])
    dp[i+1, 2] = max(dp[i+1, 2], dp[i, 0] + abc[i+1][2], dp[i, 1] + abc[i+1][2])
print(max(dp[N-1, :]))

Submission status: Runtime Error

Solution code:
n = int(input())
dp = [[[0, -1]] * 3 for _ in range(n)]
abc = [list(map(int, input().split())) for _ in range(n)]
abc = [*zip(*abc)]
a = [*abc[0]]
b = [*abc[1]]
c = [*abc[2]]
dp[0] = [[a[0], 0], [b[0], 1], [c[0], 2]]

for i in range(1, n):
    for j in range(3):
        if dp[i - 1][j][1] == 0:
            for k in [1, 2]:
                t = (b[i] if k == 1 else c[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]
        elif dp[i - 1][j][1] == 1:
            for k in [2, 0]:
                t = (c[i] if k == 2 else a[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]
        else:
            for k in [0, 1]:
                t = (b[i] if k == 1 else a[i])
                if dp[i - 1][j][0] + t > dp[i][j][0]:
                    dp[i][j] = [dp[i - 1][j][0] + t, k]


print(max([i[0] for i in dp[-1]]))

Submission status: Runtime Error

Solution code:
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

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


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

Submission status: Runtime Error

Solution code:
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)
print(dp)

Submission status: Runtime Error

Solution code:
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)

Submission status: Runtime Error

Solution code:
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)
print(dp)

Submission status: Runtime Error

Solution code:
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[k][i]+abc[i+1][j])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(input())

    dp = [0] * 3
    n_dp = [0] * 3
    for _ in range(N):
        a = list(map(int, readline().split()))
        for j in range(3):
            n_dp[j] = max(dp[j-2] + a[j], dp[j-1] + a[j])
        dp = n_dp.copy()

    print(max(dp))


main()

Submission status: Runtime Error

Solution code:
N = int(input())
a, b, c = (list() for _ in range(3))
for n in range(N):
  i,j,k = map(int, input().split())
  a.append(i)
  b.append(j)
  c.append(k)
    
dp = dict()
dp[0] = {key: 0 for key in [0,1,2]}
exc = {key: sorted([(key+i)%3 for i in range(1,3)]) for key in range(3)}

for d in range(0, N):
    dp[d+1] = dict()
    for s in [0,1,2]:
        dp[d+1][s] = max([dp[d][e]+value[s][d] for e in exc[s]])
    
print(dp[N][max(dp[N])])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = [[0]*3 for i in range(N)]

for i in range(N):
  a[i] = [int(i) for i in input().split()] 

def f(n, i):
  if n ==0:
    return a[0][i]
  i1 = (i+1) % 3
  i2 = (i+2) % 3
  if F[n][i]:
    return F[n][i]
  F[n][i] = max(f(n-1, i1), f(n-1, i2)) + a[n][i] 
  return F[n][i]  

F =[[None]*3 for _ in range(N)]

print(max(f(N-1, 0), f(N-1,1), f(N-1,2)))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
dp=[[0,0,0] for i in range(n)]
dp[0]=l[0]
def dp1(x):
  if dp[x]!=[0,0,0]:
    return dp[x]
  else:
    dp2=dp1(x-1)
    ansa=l[x][0]+max(dp2[1],dp2[2])
    ansb=l[x][1]+max(dp2[0],dp2[2])
    ansc=l[x][2]+max(dp2[1],dp2[1])
    dp[x]=[ansa,ansb,ansc]
    return dp[x]
print(dp1(n-1))

Submission status: Runtime Error

Solution code:
def holiday(n):
    old_dp = [0 for i in range(3)]
    for i in range(n):
        new_dp = [0 for i in range(n)]
        c = list(map(int, input().rstrip().split()))
        for i in range(3):
            for j in range(3):
                if i!=j:
                    new_dp[j] = max(new_dp[j], old_dp[i] + c[j])

        old_dp = new_dp
    return max(old_dp[0], old_dp[1], old_dp[2])

n = int(input().rstrip())

print(holiday(n))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 10 08:56:23 2019

@author: avina
"""

n = int(input())
l = []
for i in range(n):
    a,b,c = map(int, input().split())
    l.append((a,b,c))
dp = []
for i in range(n):
    dp.append([0,0,0])
dp[0] = [l[0][0],l[0][1],l[0][2]]

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

Submission status: Runtime Error

Solution code:
n = int(input())
vac = []
for i in range(n):
    arr =  [int(x) for x in input().strip().split()]
    vac.append(arr)
dp = {}
dp[0] = vac[0]

def solve(n):
    if n in dp:
        return dp[n]
    prev = solve(n-1)
    dp[n] = [None, None, None]
    dp[n][0] = max(prev[1],prev[2])+vac[n][0]
    dp[n][1] = max(prev[0],prev[2])+vac[n][1]
    dp[n][2] = max(prev[1],prev[0])+vac[n][2]
    return dp[n]

res = solve(n-1)
print(max(res))

Submission status: Runtime Error

Solution code:
N = int(input())

A = [map(int, input().split())]
B = [map(int, input().split())]
C = [map(int, input().split())]

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

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

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

print(max(dp[-1]))

Submission status: Runtime Error

Solution code:
Welcome to fish, the friendly interactive shell
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py 
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
kuwanakengo@kuwanakengonoMacBook ~/python> 
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py 3
10 40 70
20 50 80
30 60 90
fish: Unknown command 10
fish: 
10 40 70
^
fish: Unknown command 20
fish: 
20 50 80
^
fish: Unknown command 30
fish: 
30 60 90
^
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
  File "test2.py", line 17
    dp[i][j] = max(dp[i-1][0], dp[i-1][1)+A[i][j]
                                        ^
SyntaxError: invalid syntax
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
3
10 40 70
20 50 80
30 60 90
3
[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
3
10 40 70
20 50 80
30 60 90
Traceback (most recent call last):
  File "test2.py", line 18, in <module>
    print(mas(dp[n]))
NameError: name 'mas' is not defined
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
3
10 40 70
20 50 80
30 60 90
Traceback (most recent call last):
  File "test2.py", line 18, in <module>
    print(max(dp[n]))
IndexError: list index out of range
kuwanakengo@kuwanakengonoMacBook ~/python> 
python3 test2.py
3
10 40 70
20 50 80
30 60 90
[[10, 40, 70], [90, 120, 120], [150, 180, 210]]
kuwanakengo@kuwanakengonoMacBook ~/python> python3 test2.py
3
10 40 70
20 50 80
30 60 90
210
kuwanakengo@kuwanakengonoMacBook ~/python>

Submission status: Runtime Error

Solution code:
N=int(input())
a=[0]*N
b=[0]*N
c=[0]*N

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

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
ary = [list(map(int,input().split())) for _ in range(n)]
ary = np.array(ary)
dp = np.zeros((n,3))
dp[0] = ary[0]
for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if k == j:continue
            check = dp[i][j] + ary[i+1][k]
            if check > dp[i+1][k]:
                dp[i+1][k] = check
print(int(max(dp[n-1])))