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: Wrong Answer

Solution code:
import numpy as np
def dprint(*args):
  if debug:
    if len(args)==1:
      print(args[0])
    else:
      print(args)

debug = False
if debug:
  N=3
  ABC=[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
else:
  N = int(input())
  ABC=[]
  for i in range(N):
    ABC.append(list(map(int,input().split())))

print(N,ABC)

# i -> 1 to N
# ABC -> 012

H = np.zeros((N,3))
H[0]=ABC[0]


for j in range(1,N):
  H[j][0]=max(H[j][0], H[j-1][1]+ABC[j][0], H[j-1][2]+ABC[j][0])
  H[j][1]=max(H[j][1], H[j-1][0]+ABC[j][1], H[j-1][2]+ABC[j][1])
  H[j][2]=max(H[j][2], H[j-1][0]+ABC[j][2], H[j-1][1]+ABC[j][2])

print(max(H[-1]))

Submission status: Wrong Answer

Solution code:
def vacation(mat):
    temp = [0] * 3
    dp = mat[0]
    for i in range(1, len(mat)):
        temp[0] = mat[i][0] + max(dp[1], dp[2])
        temp[1] = mat[i][1] + max(dp[0], dp[2])
        temp[2] = mat[i][2] + max(dp[0], dp[1])
        dp = temp[:]
    print(dp)
    return max(dp)


if __name__ == '__main__':
    n = int(input())
    mat = [[0] * 3 for _ in range(n)]
    for i in range(n):
        mat[i] = list(map(int, input().split()))

    print(vacation(mat))

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[[0]*3 for _ 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][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: Wrong Answer

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]*N
selected = [0]*N
ans = []
def func(start):
    if start == a[0]:
        dp[0] = a[0]
        selected[0] = 1
    if start == b[0]:
        dp[0] = b[0]
        selected[0] = 2
    if start == c[0]:
        dp[0] = c[0]
        selected[0] = 3
    
    for i in range(0, N-1):
        if selected[i] == 1:
            dp[i+1] = max(dp[i] + b[i+1], dp[i] + c[i+1])
            if dp[i+1] == dp[i] + b[i+1]:
                selected[i+1] = 2
            else:
                selected[i+1] = 3
        if selected[i] == 2:
            dp[i+1] = max(dp[i] + c[i+1], dp[i] + a[i+1])
            if dp[i+1] == dp[i] + c[i+1]:
                selected[i+1] = 3
            else:
                selected[i+1] = 1
        if selected[i] == 3:
            dp[i+1] = max(dp[i] + a[i+1], dp[i] + b[i+1])
            if dp[i+1] == dp[i] + a[i+1]:
                selected[i+1] = 1
            else:
                selected[i+1] = 2
    ans.append(dp[N-1])

for start in [a[0], b[0], c[0]]:
    func(start=start)

print(max(ans))

Submission status: Wrong Answer

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] * (N+10)
dp[0] = max(a[0], b[0], c[0])
for i in range(1, N):
    if dp[i-1] == a[i-1]:
        dp[i] = max(b[i], c[i])
    elif dp[i-1] == b[i-1]:
        dp[i] = max(a[i], c[i])
    else:
        dp[i] = max(a[i], b[i])
print(sum([dp[i] for i in range(0, N)]))

Submission status: Wrong Answer

Solution code:

n = int(input())
dp = [[0 for _ in range(3)] for _ in range(n+1)]
ls  = [[1,2],[0,2],[0,1]]
for i in range(1,n+1):
    day = list(map(int,input().split()))
    dp[i][0] = day[0] + max(dp[i-1][1],dp[i][2])
    dp[i][1] = day[1] + max(dp[i-1][0],dp[i][2])
    dp[i][2] = day[2] + max(dp[i-1][0],dp[i][1])
print(max(dp[n]))

Submission status: Wrong Answer

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

for i in range(1,l):
    z = list(map(int,input().split()))
    x[i][0] = max(z[0]+x[i-1][1],z[0]+x[i-1][2])
    x[i][1] = max(z[1]+x[i-1][0],z[1]+x[i-1][2])
    x[i][2] = max(z[2]+x[i-1][0],z[0]+x[i-1][1])

print(max(x[-1]))

Submission status: Wrong Answer

Solution code:
l = int(input())
x = list(map(int,input().split()))

c = max(x)
for i in range(len(x)):
    if c == x[i]:
        y = i
        
#print(y)
for i in range(1,l):
    x = list(map(int,input().split()))
    #print(y)
    x[y] = 0
    #print(x)
    z = max(x)
    c += z
    for k in range(len(x)):
        if z == x[k]:
            y = k
            break
    #print(z)

print(c)

Submission status: Wrong Answer

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

for _ in range(N):
    a, b, c = map(int, input().split())
    l.append([a,b,c])
dp = [0]*N
choice = [-1] * N
for i in range(3):
    tmp = l[0][i]
    if tmp > dp[0]:
        dp[0] = tmp
        choice[0] = i

for i in range(1, N):
    for j in range(3):
        tmp = l[i][j] + dp[i-1]
        if tmp > dp[i] and choice[i-1] != j:
            dp[i] = tmp
            choice[i] = j
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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


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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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


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

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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


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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

felicidade = []

for x in range(n):
    felicidade.append(list(map(int,input().split())))

DP = [[0,0] for i in range(n)]

if n == 1:
    print(max(felicidade[0]))

else:
    maior = 0
    for x in range(3):
        if felicidade[0][x] > maior:
            maior = felicidade[0][x]
            DP[0][1] = maior
            DP[0][0] = x


    maior = 0
    for x in range(3):
        if felicidade[1][x] > maior and x != DP[0][0]:
            maior = felicidade[1][x]
            DP[1][1] = maior + DP[0][1]
            DP[1][0] = x

    for x in range(2,n):
        maior = 0
        for k in range(3):
            if felicidade[x][k] > maior and k != DP[x-1][0]:
                maior = felicidade[x][k]
                DP[x][1] = maior + DP[x-1][1]
                DP[x][0] = k

    print(DP[-1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())

felicidade = []

for x in range(n):
    felicidade.append(list(map(int,input().split())))

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

if n == 1:
    print(max(felicidade[0]))

elif n == 2:
    print(max(felicidade[0] + max(felicidade[1])))

else:
    maior = max(felicidade[0])
    dp[0][0] = max(dp[0][0],dp[0][0] +  maior)

    if maior == felicidade[0][0]:
        dp[0][1] = 0
    elif maior == felicidade[0][1]:
        dp[0][1] = 1
    elif maior  == felicidade[0][2]:
        dp[0][1] = 2

    maior = max(felicidade[1])
    dp[1][0] = max(dp[0][0],dp[0][0] + maior)

    if maior == felicidade[1][0]:
        dp[1][1] = 0
    elif maior == felicidade[1][1]:
        dp[1][1] = 1
    elif maior  == felicidade[1][2]:
        dp[1][1] = 2

    for x in range(2,n):
        for y in range(3):
            if dp[x-1][1] != dp[x-2][1]:
                if dp[x][0] + felicidade[x][0] == felicidade[x][0]:
                    dp[x][1] = 0
                elif dp[x][0] + felicidade[x][0] == felicidade[x][1]:
                    dp[x][1] = 1
                elif dp[x][0] + felicidade[x][0] == felicidade[x][2]:
                    dp[x][1] = 2
                dp[x][0] = max(dp[x][0], dp[x-1][0] + felicidade[x][y])

            else:
                felicidade[x][dp[x-1][1]] = 0
                if dp[x][0] + felicidade[x][0] == felicidade[x][0]:
                    dp[x][1] = 0
                elif dp[x][0] + felicidade[x][0] == felicidade[x][1]:
                    dp[x][1] = 1
                elif dp[x][0] + felicidade[x][0]  == felicidade[x][2]:
                    dp[x][1] = 2
                dp[x][0] = max(dp[x][0], dp[x-1][0] + felicidade[x][y])

    print(dp[-1][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
action = []
for i in range(n):
    action.append([int(i) for i in input().split()])
df = []
df.append(max(action[0]))
prev = action[0].index(max(action[0]))
for i in range(1, n):
    tgt = max([action[i][j] for j in range(len(action[i])) if j != prev])
    prev = action[i].index(tgt)
    df.append(tgt)
print(sum(df))

Submission status: Wrong Answer

Solution code:
N = int(input())

max_a = [0] * N
max_b = [0] * N
max_c = [0] * N

for i in range(0, N):
    a, b, c = map(int, input().split())
    max_a[i] = max(max_b[i - 1] + a, max_c[i-1] + a)
    max_b[i] = max(max_a[i - 1] + b, max_c[i - 1] + b)
    max_c[i] = max(max_a[i - 1] + c, max_b[i - 1] + c)

print(max(max_a[-1], max_b[-1], max_c[-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
dp={}
l1=list(map(int,input().split()))
dp[1]=[max(l1),l1.index(max(l1))+1]

for val in range(2,n+1):
    dp[val]=[0,4]
for val2 in range(2,n+1):
    l=list(map(int,input().split()))
    l[dp[val2-1][1]-1]=0
    dp[val2]=[max(dp[val2][0],dp[val2-1][0]+max(l)),l.index(max(l))+1]
print(dp[n][0])

Submission status: Wrong Answer

Solution code:
n=int(input())
dp={}
l1=list(map(int,input().split()))
dp[1]=[max(l1),l1.index(max(l1))+1]

for val in range(2,n+1):
    dp[val]=[0,4]
for val2 in range(2,n+1):
    l=list(map(int,input().split()))
    flag=dp[val2-1][1]
    if(flag==1):
        vl=max(l[1],l[2])
    elif(flag==2):
        vl=max(l[0],l[2])
    else:
        vl=max(l[1],l[0])
    dp[val2]=[max(dp[val2][0],dp[val2-1][0]+vl),l.index(vl)+1]
print(dp[n][0])

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
lst = []

for _ in range(n):
  l = list(map(int, input().split()))
  lst.append(l)
  
hp = [[0] * 3 for _ in range(n)]

plst = list(itertools.permutations([_ for _ in range(3)], 2))

for _ in range(0, n):
    for i in plst:
      hp[_][i[1]] = max(hp[_-1][i[0]] + lst[_][i[1]],hp[_][i[1]])

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

Submission status: Wrong Answer

Solution code:
n = int(input())
abc_list = [list(map(int, input().split())) for i in range(n)]
dp = [0] * n
dp[0] = max(abc_list[0])
abc_max_index = abc_list[0].index(max(abc_list[0]))


for i in range(1, n):
    abc_list[i][abc_max_index] = -1
    abc_max = max(abc_list[i])
    abc_max_index = abc_list[i].index(abc_max)
    dp[i] = dp[i - 1] + abc_max

print(dp[n - 1])

Submission status: Wrong Answer

Solution code:

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

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
#  入力
n = int(input())
abcList = []
for i in range(n):
    abcList.append(list(map(int, input().split())))


#  dpテーブルの初期化
dp = [abcList[0]]

#  dpテーブルの完成
for i in range(1, n):
    dp.append(
        [
            max(dp[-1][1] + abcList[i][0], dp[-1][2] + abcList[i][0]),
            max(dp[-1][0] + abcList[i][1], dp[-1][2] + abcList[i][1]),
            max(dp[-1][1] + abcList[i][2], dp[-1][0] + abcList[i][2]),
        ]
    )

for d in dp:
    print(d)

Submission status: Wrong Answer

Solution code:
#  入力
#  n = int(input())
#  abcList = []
#  for i in range(n):
#      abcList.append(list(map(int, input().split())))

n = 7
abcList = [[6, 7, 8], [8, 8, 3], [2, 5, 2], [7, 8, 6], [4, 6, 8], [2, 3, 4], [7, 5, 1]]

#  dpテーブルの初期化
dp = [abcList[0]]

#  dpテーブルの完成
for i in range(1, n):
    dp.append(
        [
            max(dp[-1][1] + abcList[i][0], dp[-1][2] + abcList[i][0]),
            max(dp[-1][0] + abcList[i][1], dp[-1][2] + abcList[i][1]),
            max(dp[-1][1] + abcList[i][2], dp[-1][0] + abcList[i][2]),
        ]
    )

for d in dp:
    print(d)

Submission status: Wrong Answer

Solution code:
#  入力
n = int(input())
abcList = []
for i in range(n):
    abcList.append(list(map(int, input().split())))

#  dpテーブルの初期化
dp = [abcList[0]]

#  dpテーブルの完成
for i in range(1, n):
    dp.append(
        [
            max(dp[-1][1] + abcList[i][1], dp[-1][2] + abcList[i][2]),
            max(dp[-1][0] + abcList[i][0], dp[-1][2] + abcList[i][2]),
            max(dp[-1][1] + abcList[i][1], dp[-1][0] + abcList[i][0]),
        ]
    )

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
reward=[]
for i in range(n):
    a=list(map(int,input().split()))
    reward.append(a)
tmp=0
sum=0
for i in range(n):
    a0=reward[i][0]
    a1=reward[i][1]
    a2=reward[i][2]
    if tmp==0:
        if a2>=a1:
            tmp=2
            sum+=a2
        else:
            tmp=1
            sum+=a1
    elif tmp==1:
        if a0>a2:
            tmp=0
            sum+=a0
        else:
            tmp=2
            sum+=a2
    else:
        if a0>a1:
            tmp=0
            sum+=a0
        else:
            tmp=1
            sum+=a1

tmp=1
sum1=0
for i in range(n):
    a0=reward[i][0]
    a1=reward[i][1]
    a2=reward[i][2]
    if tmp==0:
        if a2>=a1:
            tmp=2
            sum1+=a2
        else:
            tmp=1
            sum1+=a1
    elif tmp==1:
        if a0>a2:
            tmp=0
            sum1+=a0
        else:
            tmp=2
            sum1+=a2
    else:
        if a0>a1:
            tmp=0
            sum1+=a0
        else:
            tmp=1
            sum1+=a1

tmp=2
sum2=0
for i in range(n):
    a0=reward[i][0]
    a1=reward[i][1]
    a2=reward[i][2]
    if tmp==0:
        if a2>=a1:
            tmp=2
            sum2+=a2
        else:
            tmp=1
            sum2+=a1
    elif tmp==1:
        if a0>a2:
            tmp=0
            sum2+=a0
        else:
            tmp=2
            sum2+=a2
    else:
        if a0>a1:
            tmp=0
            sum2+=a0
        else:
            tmp=1
            sum2+=a1
        
print(max(sum,max(sum1,sum2)))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

N = int(input())
act = []
for i in range(N):
	act.append([int(x) for x in input().split()])

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

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

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

print(m)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

N = int(input())
act = []
for i in range(N):
	act.append([int(x) for x in input().split()])

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

for i in range(0, 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] + act[i][k])

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

print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[[]*n for i in range(3)]

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
abcs = [None for _ in range(n)]

dp = [[0, 0, 0] for ___ in range(n)]
# dp[i][j][k] i 番目 連続/未連続 abc
for i in range(n):
    abcs[i] = list(map(int, input().split()))
for i in range(n):
    for k in range(3):  # next abc
        for j in range(3):  # previous abc
            if k != j:
                dp[i][k] = max(dp[i][k], dp[i - 1][j] + abcs[i][k])
print(max(dp[i]))
# これは三日以上
# for i in range(n):
#     for k in range(3):  # next abc
#         for j in range(2):  # j == 0: 未連続, j == 1: 連続
#             for l in range(3):  # previous abc
#                 if k == l and j == 1:
#                     dp[i][j][k] = dp[i - 1][0][l] + abcs[i][k]
#                 elif k != l:
#                     dp[i][j][k] = max(dp[i][j][k],
#                                       dp[i - 1][j][l] + abcs[i][k])
#                 print(dp[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# DPテーブルは選択分拡張する
dp = [[0,0,0] for i in range(N+1)]

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
c = [0 for _ in range(n)]
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())
ans = 0
now = "None"

for i in range(n):
    if now == "None":
        if a[i] < b[i]:
            if b[i] < c[i]:
                ans += c[i]
                now = "C"
            else:
                ans += b[i]
                now = "B"
        elif a[i] < c[i]:
            ans += c[i]
            now = "C"
        else:
            ans += a[i]
            now = "A"
    elif now == "A":
        if b[i] < c[i]:
            ans += c[i]
            now = "C"
        else:
            ans += b[i]
            now = "B"
    elif now == "B":
        if a[i] < c[i]:
            ans += c[i]
            now = "C"
        else:
            ans += a[i]
            now = "A"
    else:
        if a[i] < b[i]:
            ans += b[i]
            now = "B"
        else:
            ans += a[i]
            now = "A"
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
z=4
sumi=0
for i in range(n):
    a=list(map(int,input().split()))
    maxi=max(a)
    if z==a.index(maxi):
        a.pop(z)
        sumi=sumi+max(a)
        z=a.index(max(a))
    else:
        sumi=sumi+max(a)
        z = a.index(max(a))
print(sumi)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
ac = []
for i in range(n):
    i = list(map(int,input().split()))
    ac.append(i)
ac = np.array(ac)
dp = [0]*n

cnt = 3 #二個目のfor文で0~2と被らないようにするため
for j in range(n):
    tmp = 0
    m = 0
    for k in range(3):
        if k != cnt:
            if tmp <= ac[j][k]:
                tmp = ac[j][k]
                m = k
    cnt = m
    dp[j] = tmp

print(sum(dp))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
ac = []
for i in range(n):
    i = list(map(int,input().split()))
    ac.append(i)
ac = np.array(ac)
dp = [0]*n

cnt = 3 #二個目のfor文で0~2と被らないようにするため
for j in range(n):
    tmp = 0
    m = 0
    for k in range(3):
        if k != cnt:
            if tmp < ac[j][k]:
                tmp = ac[j][k]
                m = k
    cnt = m
    dp[j] = tmp

print(sum(dp))

Submission status: Wrong Answer

Solution code:
import numpy as np
#N,K = map(int,input().split())
N = int(input())
a,b,c = map(int,input().split())
ab,bb,cb = a,b,c
ma = max(a,b,c)
ans = ma
for i in range(1,N):
  a,b,c = map(int,input().split())
  if ma == ab:
    a = 0
  elif ma == bb:
    b = 0
  elif ma == cb:
    c = 0
  ma =max(a,b,c)
  ab,bb,cb = a,b,c
  ans += ma  
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
hahaha=0
for i in range(a):
    r=str(input()).split()
    m=[int(u) for u in r]
    hahaha+=max(m)
print(hahaha)

Submission status: Wrong Answer

Solution code:
N= int(input())

arr = [list(map(int,input().split())) for _ in range(N)]
dp = [ list([0,0,0]) for i in range(N)]
for i,l in enumerate(arr):
  if i == 0:
    dp[0] = l
    continue
  dp[i] = [max(dp[i-1][1:])+l[1], max(dp[i-1][0],dp[i-1][2])+l[1],max(dp[i-1][:2])+l[2]]
print(max(dp[-1]))
#print(dp)

Submission status: Wrong Answer

Solution code:
N= int(input())

arr = [list(map(int,input().split())) for _ in range(N)]
dp = [0,0,0]
for l in arr:
    dp = [max(dp[1:])+l[1], max(dp[0],dp[2])+l[1],max(dp[:3])+l[2]]
print(max(dp))
#print(dp)

Submission status: Wrong Answer

Solution code:
N= int(input())
import numpy as np
arr = np.array([input().split() for _ in range(N)], dtype=np.int8)
dp = np.zeros_like(arr)
for i, arr_ in enumerate(arr):
    for j in range(len(arr_)):
        if i == 0:
            dp[i][j] = arr_[j]
            continue
        for k in range(len(arr_)):
            if j != k:
                dp[i][j] = max(dp[i-1][k] + arr_[j], dp[i][j])
print(np.max(dp[-1]))
#print(dp)

Submission status: Wrong Answer

Solution code:
n = int(input())

days = []

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

'''
days = [
    [10, 40, 70], 
    [20, 50, 80], 
    [30, 60, 90]
]
'''

dp = days[0]
temp = [0, 0, 0]

for i in range(1, n): # 2
    temp = [0, 0, 0]
    for j in range(3): # 0, 1, 2
        if j == 0:
            # dp = [90, 120, 120]
            # days[i] = [30, 60, 90]
            temp[j] = max(dp[1] + days[i][j], dp[2] + days[i][j])
        elif j == 1:
            temp[j] = max(dp[0] + days[i][j], dp[2] + days[i][j])
        elif j == 2:
            temp[j] = max(dp[0] + days[i][j], dp[1] + days[i][j])

print(max(dp))

Submission status: Wrong Answer

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

for j in range(N):
    a.append(list(map(int,input().split())))

b[0][0] = 0
b[0][1] = 4


if b[0][0] < a[0][0]:
    b[0][0] = a[0][0]
    b[0][1] = 0
if b[0][0] < a[0][1]:
    b[0][0] = a[0][1]
    b[0][1] = 1
if b[0][0] < a[0][2]:
    b[0][0] = a[0][2]
    b[0][1] = 2

if N >= 2:
    for i in range(N-1):
        b[i+1][0] = 0
        if (b[i+1][0] < a[i+1][0] and (not b[i][0] == 0)):
            b[i+1][0] = a[i+1][0]
            b[i+1][1] = 0
        if (b[i+1][0] < a[i+1][1] and (not b[i][1] == 1)):
            b[i+1][0] = a[i+1][1]
            b[i+1][1] = 1
        if (b[i+1][0] < a[i+1][2] and (not b[i][1] == 2)):
            b[i+1][0] = a[i+1][2]
            b[i+1][1] = 2
        b[i+1][0] = b[i][0] + b[i+1][0]

print(b[N-1][0])

Submission status: Wrong Answer

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

for j in range(N):
    a.append(list(map(int,input().split())))

b[0][0] = 0
b[0][1] = 4


if b[0][0] < a[0][0]:
    b[0][0] = a[0][0]
    b[0][1] = 0
if b[0][0] < a[0][1]:
    b[0][0] = a[0][1]
    b[0][1] = 1
if b[0][0] < a[0][2]:
    b[0][0] = a[0][2]
    b[0][1] = 2

    for i in range(N-1):
        b[i+1][0] = 0
        if (b[i+1][0] < a[i+1][0] and (not b[i][0] == 0)):
            b[i+1][0] = a[i+1][0]
            b[i+1][1] = 0
        if (b[i+1][0] < a[i+1][1] and (not b[i][1] == 1)):
            b[i+1][0] = a[i+1][1]
            b[i+1][1] = 1
        if (b[i+1][0] < a[i+1][2] and (not b[i][1] == 2)):
            b[i+1][0] = a[i+1][2]
            b[i+1][1] = 2
        b[i+1][0] = b[i][0] + b[i+1][0]

print(b[N-1][0])

Submission status: Wrong Answer

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

dp = [[0,0,0],u[0]]
for i in range(2,n+1):
    dp.append([0,0,0])
for i in range(2,n+1):
    dp[i][0]=max(dp[i-1][1]+u[i][0],dp[i-1][2]+u[i][0])
    dp[i][1]=max(dp[i-1][2]+u[i][1],dp[i-1][0]+u[i][1])
    dp[i][2]=max(dp[i-1][0]+u[i][2],dp[i-1][1]+u[i][2])

print(max(dp[n]))

Submission status: Wrong Answer

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

dp=[0]*N
dpp=["a"]*N
pt=["a","b","c"]

for i in range(N):
  if i==0:
    max_index=abc[i].index(max(abc[i]))
    dpp[i]=pt[max_index]
    dp[i]=abc[i][max_index]
  else:
    max_index=abc[i].index(max(abc[i]))
    dpp[i]=pt[max_index]
    if dpp[i-1]==dpp[i]:
      abc[i].pop(max_index)
      max_index=abc[i].index(max(abc[i]))
      dpp[i]=pt[max_index]
    dp[i]=dp[i-1]+abc[i][max_index]
print(dp[-1])

Submission status: Wrong Answer

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):
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]+a[i+1], dp[i][2]+a[i+1])
    dp[i+1][0] = max(dp[i+1][0], dp[i][0]+b[i+1], dp[i][2]+b[i+1])
    dp[i+1][0] = max(dp[i+1][0], dp[i][0]+c[i+1], dp[i][1]+c[i+1])
print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())

l = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	l.append((a, i, 'a'))
	l.append((b, i, 'b'))
	l.append((c, i, 'c'))

feed = [None] * (n + 2)
ans = 0
for i in sorted(l, reverse=True):
	curr = i[1] + 1
	kind = i[2]
	if feed[curr] is None and not ( feed[curr- 1] is kind or feed[curr + 1] is kind):
		ans += i[0]
		feed[curr] = kind

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[max(i-1,0)][(j+1)%3],DP[max(i-1,0)][(j+2)%3])
print(max(DP[N-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(1,N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[N-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(N):
	for j in range(3):
		DP[i][j]=int(ABC[i][j])+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[N-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
happiness = [list(map(int, input().split())) for i in range(n)]
dp = [[0] * 3 for i in range(n + 1)]

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

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

Submission status: Wrong Answer

Solution code:
s,t=0,-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:
        if a>=b and a>=c:
            s=a
            t=1
        elif b>=c:
            s=b
            t=2
        else:
            s=c
            t=3
print(s)

Submission status: Wrong Answer

Solution code:
s,t=0,-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)
        if a>=b and a>=c:
            t=1
        elif b>=c:
            t=2
        else:
            t=3
print(s)

Submission status: Wrong Answer

Solution code:
s,t=0,-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)
        if a>=b and a>=c:
            t=1
        elif b>=c:
            t=2
        else:
            t=3
print(s)