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 sys
def input():
    return sys.stdin.readline()[:-1]

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

inf = 10**9+7
dp = [[0] * 3 for _ in range(N+10)]
dp[0] = [ABC[0][0],ABC[0][1],ABC[0][2]]

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

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

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]
    dpc[i] = max( dpa[i-1]+c[i], dpb[i-1])+c[i]

print(max(dpa[-1], dpb[-1], dpc[-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())

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

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

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

dp = [[0]*3]*N

#初期値(添字0：a,添字1：b,添字2：cとする)
dp[0][0] = siawaseList[0][0]
dp[0][1] = siawaseList[0][1]
dp[0][2] = siawaseList[0][2] 

for i in range(1,N):
    dp[i][0] = max(dp[i-1][1]+siawaseList[i][0],dp[i-1][2]+siawaseList[i][0])
    dp[i][1] = max(dp[i-1][0]+siawaseList[i][1],dp[i-1][2]+siawaseList[i][1])
    dp[i][2] = max(dp[i-1][0]+siawaseList[i][2],dp[i-1][1]+siawaseList[i][2])
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

Submission status: Wrong Answer

Solution code:
def fun(a):
    n = len(a)
    c = [c[:] for c in [[0]*3]*n]
    for i in range(3):
        k = i
        c[0][i] = a[0][i]
        for j in range(1, len(a)):
            temp = max(a[j][h] for h in range(3) if h != k)
            k = a[j].index(temp)
            c[j][i] = temp+c[j-1][i]
    # print(c)
    return max(c[-1])


n = int(input())
a = []
# print(a)
for i in range(n):
    a.append([int(x) for x in input().split(" ")])
# print(a)
print(fun(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
for i in range(n):
    x, y, z = map(int, input().split())
    a.append(x)
    b.append(y)
    c.append(z)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
for i in range(n):
    x, y, z = map(int, input().split())
    a.append(x)
    b.append(y)
    c.append(z)

print(a)
print(b)
print(c)
dp = [[0 for i in range(3)] 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):
    print(dp[i],dp[i-1],a[i],b[i],c[i])
    print(dp[i],dp[i-1],a[i],b[i],c[i])
    print(dp[i],dp[i-1],a[i],b[i],c[i])
    print(dp[i],dp[i-1],a[i],b[i],c[i])

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

Submission status: Wrong Answer

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

print(abc)

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

def solve(abc):
    dp = np.zeros((N, 3), dtype='int32')  # [[Ai, Bi, Ci]...]

    for j in range(3):
        dp[0][j] = abc[0][j]
    if N == 1:
        return dp

    for i in range(N-1):
        for j in range(3):
            dp[i+1][j] = abc[i+1][j] + np.max(dp[i][T[j]])

    print(dp)
    return dp

print(max(solve(abc)[N-1]))


"""
ちゃんと解いたVer
"""

Submission status: Wrong Answer

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

# print(abc)

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

def solve(abc):
    dp = np.zeros((N, 3), dtype='int32')  # [[Ai, Bi, Ci]...]

    is_odd = 1 - N % 2

    for j in range(3):
        dp[0][j] = abc[0][j]
    if N == 1:
        return dp

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

    for i in range(N-2):
        if i % 2 != is_odd:
            continue
        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]

    return dp

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


"""

"""

Submission status: Wrong Answer

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

# print(abc)

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

def solve(abc):
    dp = np.zeros((N, 3), dtype='int32')  # [[Ai, Bi, Ci]...]

    for j in range(3):
        dp[0][j] = abc[0][j]
    if N == 1:
        return dp

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

    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]

    return dp

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


"""

"""

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
C = []
for i in range(N):
    tmp_a,tmp_b,tmp_c = map(int,input().split())
    A.append(tmp_a)
    B.append(tmp_b)
    C.append(tmp_c)

dp = [[0 for j in range(3)] for i in range(N)]
dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

if N == 1:
    print(max(inputs))
else:
    # dp[i]には1, 2, 3を選択した時の幸福度の最大値を入れている
    dp = [[0, 0, 0] for _ in range(N)]
    dp[0] = inputs[0]
    for i in range(N):
        dp[i][0] = max(dp[i-1][1] + inputs[i][0], dp[i-1][2] + inputs[i][0])
        dp[i][1] = max(dp[i-1][2] + inputs[i][1], dp[i-1][0] + inputs[i][1])
        dp[i][2] = max(dp[i-1][0] + inputs[i][2], dp[i-1][1] + inputs[i][2])

    print(dp)

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int,input().split())) for i in range(n)]
dp = [0]*n
dp[0] = 0
yesterday=-1
for i in range(n):
  for activity in [0,1,2]:
    if i == 0:
      if dp[i] < abc[i][activity]:
        tmp = activity
        dp[i] = max(dp[i],abc[i][activity])
    elif activity != yesterday:
      if dp[i] < abc[i][activity]+dp[i-1]:
        tmp = activity
        dp[i] = max(dp[i],abc[i][activity]+dp[i-1])
  yesterday = tmp
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int,input().split())) for i in range(n)]
dp = [0]*n
dp[0] = 0
yesterday=-1
for i in range(n):
  for activity in [0,1,2]:
    if activity != yesterday and dp[i] < abc[i][activity]+dp[i-1]:
        tmp = activity
        if i>0:
          dp[i] = max(dp[i],abc[i][activity]+dp[i-1])
        else:
          dp[i] = max(dp[i],abc[i][activity])
  yesterday = tmp
print(dp[-1])

Submission status: Wrong Answer

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

dp = [0] #各日の最大の楽しみ 0:0日目の最大
former = -1
dic = {0:[1,2],1:[0,2],2:[0,1]}
ls = []
"""
for i in range(3): #最初に選んだのがi
    for j in range(1,n+1): #j日目
        if j == 1:
            dp.append(dp[j-1]+ad[j-1][i])
            former = i
        else:
            if dp[j-1]+ad[j-1][dic[former][0]] <  dp[j-1]+ad[j-1][dic[former][1]]:
                dp.append(dp[j-1]+ad[j-1][dic[former][1]])
                former = dic[former][1]
            else:
                dp.append(dp[j-1]+ad[j-1][dic[former][0]])
                former = dic[former][0]
        #print(former)
    #print(dp[1:])
    ls.append(dp[n])
    dp = [0]
print(max(ls))
"""

for i in range(3):#1日目の選択
    for j in range(2):#2日目の選択
        for k in range(1,n+1): #n日目まで
            if k == 1:
                dp.append(dp[k-1]+ad[k-1][i])
            elif k == 2:
                dp.append(dp[k-1]+ad[k-1][dic[i][j]])
            else:
                if k == 3:
                    former = dic[i][j]
                if dp[k-1]+ad[k-1][dic[former][0]] <  dp[k-1]+ad[k-1][dic[former][1]]:
                    dp.append(dp[k-1]+ad[k-1][dic[former][1]])
                    former = dic[former][1]
                else:
                    dp.append(dp[k-1]+ad[k-1][dic[former][0]])
                    former = dic[former][0]
        #print(i,j)
        #print(dp)
        ls.append(dp[n])
        dp = [0]
print(max(ls))

Submission status: Wrong Answer

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

dp = [0] #各日の最大の楽しみ 0:0日目の最大
former = -1
dic = {0:[1,2],1:[0,2],2:[0,1]}
ls = []
for i in range(3): #最初に選んだのがi
    for j in range(1,n+1): #j日目
        if j == 1:
            dp.append(dp[j-1]+ad[j-1][i])
            former = i
        else:
            if dp[j-1]+ad[j-1][dic[former][0]] <  dp[j-1]+ad[j-1][dic[former][1]]:
                dp.append(dp[j-1]+ad[j-1][dic[former][1]])
                former = dic[former][1]
            else:
                dp.append(dp[j-1]+ad[j-1][dic[former][0]])
                former = dic[former][0]
        #print(former)
    #print(dp[1:])
    ls.append(dp[n])
    dp = [0]
print(max(ls))
"""
print(ad)
"""

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    happiness = []
    for i in range(N):
        happiness.append([int(num) for num in input().split()])

    hap_total = [[0] * 3] * N
    hap_total[0] = [happiness[0][0], happiness[0][1], happiness[0][2]]


    for i in range(1, N):
        for j in range(3):
            for k in {0, 1, 2} - {j}:
                hap_total[i][j] = max(hap_total[i][j], hap_total[i-1][k] + happiness[i][j])


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b, c = [],[],[]
dpx, dpy, dpz = [0]*n, [0]*n, [0]*n
x, y, z = [None] * n, [None] * n, [None] * n

for i in range(n):
    v1, v2, v3 = map(int, input().split())
    a.append(v1)
    b.append(v2)
    c.append(v3)

x[0], y[0], z[0] = "a", "b", "c"
dpx[0], dpy[0], dpz[0] = a[0], b[0], c[0]

for i in range(1, n):
#for i in range(n):
    if x[i-1] == "a":
        if b[i] > c[i]:
            x[i] = "b"
            dpx[i] = dpx[i-1] + b[i]
        else:
            x[i] = "c"
            dpx[i] = dpx[i-1] + c[i]
    elif x[i-1] == "b":
        if a[i] > c[i]:
            x[i] = "a"
            dpx[i] = dpx[i-1] + a[i]
        else:
            x[i] = "c"
            dpx[i] = dpx[i-1] + c[i]
    elif x[i-1] == "c":
        if b[i] > a[i]:
            x[i] = "b"
            dpx[i] = dpx[i-1] + b[i]
        else:
            x[i] = "a"
            dpx[i] = dpx[i-1] + a[i]

### DPY
for i in range(1, n):
    if y[i-1] == "a":
        if b[i] > c[i]:
            y[i] = "b"
            dpy[i] = dpy[i-1] + b[i]
        else:
            y[i] = "c"
            dpy[i] = dpy[i-1] + c[i]
    elif y[i-1] == "b":
        if a[i] > c[i]:
            y[i] = "a"
            dpy[i] = dpy[i-1] + a[i]
        else:
            y[i] = "c"
            dpy[i] = dpy[i-1] + c[i]
    elif y[i-1] == "c":
        if b[i] > a[i]:
            y[i] = "b"
            dpy[i] = dpy[i-1] + b[i]
        else:
            y[i] = "a"
            dpy[i] = dpy[i-1] + a[i]

### DPZ
for i in range(1, n):
    if z[i-1] == "a":
        if b[i] > c[i]:
            z[i] = "b"
            dpz[i] = dpz[i-1] + b[i]
        else:
            z[i] = "c"
            dpz[i] = dpz[i-1] + c[i]
    elif z[i-1] == "b":
        if a[i] > c[i]:
            z[i] = "a"
            dpz[i] = dpz[i-1] + a[i]
        else:
            z[i] = "c"
            dpz[i] = dpz[i-1] + c[i]
    elif z[i-1] == "c":
        if b[i] > a[i]:
            z[i] = "b"
            dpz[i] = dpz[i-1] + b[i]
        else:
            z[i] = "a"
            dpz[i] = dpz[i-1] + a[i]

# print("a: " + str(a))
# print("b: " + str(b))
# print("c: " + str(c))
# print("dpx: " + str(dpx[n-1]))
# print("dpy: " + str(dpy[n-1]))
# print("dpz: " + str(dpz[n-1]))
print(max(dpx[n-1], dpy[n-1], dpz[n-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

for days in range(N):
	inp = input().split()
	c = []
	for i in inp:
		c.append(int(i))

	dp = [0, 0, 0]

	for i in range(3):
		for j in range(3):
			if i != j:
				dp[j] = max(dp[j], dp[i] + c[j])

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

Submission status: Wrong Answer

Solution code:
import copy

def abc(N, L, num, val) :
    cnt = val
    for i in range(1, N) :
        L[i][num] = 0
        cnt += max(L[i])
        num = L[i].index(max(L[i]))
    return cnt


N = int(input())
ABC = [0 for i in range(N)]

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

LA = copy.deepcopy(ABC)
LB = copy.deepcopy(ABC)
LC = copy.deepcopy(ABC)

A = abc(N, LA, 0, ABC[0][0])
B = abc(N, LB, 1, ABC[0][1])
C = abc(N, LC, 2, ABC[0][2])

print(max(A, B, C))

Submission status: Wrong Answer

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

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

cnt = max(ABC[0])
num = ABC[0].index(max(ABC[0]))

for i in range(1, N) :
    ABC[i][num] = 0
    cnt += max(ABC[i])
    num = ABC[i].index(max(ABC[i]))

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(200000)

N = int(input())
hpns = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0, 0, 0] for _ in [0]*(N)]
dp[0] = hpns[0]

def solve():
  for i in range(0,N-1):
    for j in range(3):
      for k in range(3):
        if k == j:
          continue
        else:
          print(i, j, k, dp[i][j], hpns[i+1][k])
          dp[i+1][j] = max(dp[i][k] + hpns[i+1][j], dp[i+1][j])

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

Submission status: Wrong Answer

Solution code:
import numpy as np

def calc_happiness(n, a, b, c):
    h = np.zeros((n, 3))
    h[0, 0] = a[0]
    h[0, 1] = b[0]
    h[0, 2] = c[0]

    for i in range(1, n):
        h[i, 0] = h[i-1, 1] + a[i] if h[i-1, 1] > h[i-1, 2] else h[i-1, 2] + a[i]
        h[i, 1] = h[i-1, 0] + b[i] if h[i-1, 0] > h[i-1, 2] else h[i-1, 2] + b[i]
        h[i, 2] = h[i-1, 0] + c[i] if h[i-1, 0] > h[i-1, 1] else h[i-1, 1] + c[i]

    return h

if __name__ == '__main__':
    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] = list(map(int, input().split()))

    h = calc_happiness(n, a, b, c)
    print(max(h[n-1,:]))

Submission status: Wrong Answer

Solution code:
N = int(input())

matrix = []
for _ in range(N):
    matrix.append(list(map(int, input().split())))
    
dp_matrix = [[0, 0, 0]]

for i in range(N):
    dp_matrix_list = [0, 0, 0]
    for j in range(3):
        for k in range(3):
            if (j != k) and (dp_matrix_list[j] < dp_matrix[i][j] + matrix[i][k]):
                dp_matrix_list[j] = dp_matrix[i][j] + matrix[i][k]
    dp_matrix.append(dp_matrix_list)
    
print(max(dp_matrix[-1]))

Submission status: Wrong Answer

Solution code:
def resolve():
    (N) = int(input())
    abcs = [list(map(int, input().split(" "))) for _ in range(N)]
    dps = [[0, None]] * N

    for i in range(N):
        maxv = 0
        maxidx = None
        
        for j in range(3):
            if i != 0 and dps[i-1][1] == j:
                continue
            if maxv < abcs[i][j]:
                maxv = abcs[i][j]
                maxidx = j
        
        if i == 0:
            dps[i][0] = maxv
        else:
            dps[i][0] = dps[i-1][0] + maxv

        dps[i][1] = maxidx

    print(dps[-1][0])

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    (N) = int(input())
    abcs = [list(map(int, input().split(" "))) for _ in range(N)]
    dps = [0] * N

    prev = None
    for i in range(N):
        if prev is not None:
            abcs[i][prev] = 0
        maxv = 0
        maxi = None
        for j in range(3):
            if maxv < abcs[i][j]:
                maxv = abcs[i][j]
                maxi = j
        if i == 0:
            dps[i] = maxv
        else:
            dps[i] = dps[i-1] + maxv
        prev = maxi

    print(dps[-1])

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
c = []
for i in range(n):
    m,v,p = map(int,input().split())
    a.append(m)
    b.append(v)
    c.append(p)
d = [[0]*3 for i in range(n)]
d[0][0]=a[0]
d[0][1]=b[0]
d[0][2]=c[0]
for i in range(n):
    for j in range(3):
        if j == 0:
            d[i][j] = max(d[i-1][1],d[i-1][2]) + a[i]
        elif j == 1:
            d[i][j] = max(d[i-1][0],d[i-1][2]) + b[i]
        else:
            d[i][j] = max(d[i-1][0],d[i-1][1]) + c[i]
print(max(d[-1][0],d[-1][1],d[-1][2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Solution code:
import sys

n = int(input())
type_n = 3
happiness_list = []
dp = [[0,0,0] for i in range(n+1)]

for i in range(n):
  happiness_list.append([int(x) for x in input().split(" ")])

for i in range(type_n):
  dp[0][i] = 0

for i in range(0, n):
  for j in range(type_n):
    temp = happiness_list[i][j]
    happiness_list[i][j] = 0
    dp[i+1][j] = dp[i][j] + max(happiness_list[i])
    happiness_list[i][j] = temp

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
type_n = 3
happiness_list = []
dp = [[0,0,0] for i in range(n+1)]

for i in range(n):
  happiness_list.append([int(x) for x in input().split(" ")])

for i in range(type_n):
  dp[0][i] = 0

for i in range(0, n):
  for j in range(type_n):
    temp = happiness_list[i][j]
    happiness_list[i][j] = 0
    dp[i+1][j] = dp[i][j] + max(happiness_list[i])
    happiness_list[i][j] = temp

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

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
type_n = 3
happiness_list = []
dp = [[0,0,0] for i in range(n+1)]

for i in range(n):
  happiness_list.append([int(x) for x in input().split(" ")])

for i in range(type_n):
  dp[0][i] = 0

for i in range(7, n):
  for j in range(type_n):
    temp = happiness_list[i][j]
    happiness_list[i][j] = 0
    dp[i+1][j] = dp[i][j] + max(happiness_list[i])
    happiness_list[i][j] = temp

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
type_n = 3
happiness_list = []
dp = [[0,0,0] for i in range(n)]

for i in range(n):
  happiness_list.append([int(x) for x in input().split(" ")])

for i in range(type_n):
  dp[0][i] = happiness_list[0][i]

for i in range(1, n):
  for j in range(type_n):
    temp = happiness_list[i][j]
    happiness_list[i][j] = -1
    dp[i][j] = dp[i-1][j] + max(happiness_list[i])
    happiness_list[i][j] = temp

print(max(dp[-1]))

Submission status: Wrong Answer

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,0,0]]*(N+1)
for i in range(N):
    dp[i+1][0] = max(dp[i+1][0], dp[i][1], dp[i][2]) + A[i]
    dp[i+1][1] = max(dp[i+1][1], dp[i][2], dp[i][0]) + B[i]
    dp[i+1][2] = max(dp[i+1][2], dp[i][0], dp[i][1]) + C[i]


print(max(dp[N]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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,0,0]]*(N+1)
for i in range(N):
    dp[i+1][0] = max(dp[i][1] + A[i], dp[i][2] + A[i])
    dp[i+1][1] = max(dp[i][0] + B[i], dp[i][2] + B[i])
    dp[i+1][2] = max(dp[i][0] + C[i], dp[i][1] + C[i])
    
print(max(dp[N]))

Submission status: Wrong Answer

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,0,0]]*(N+1)
for i in range(N):
    dp[i+1][1] = dp[i][0] + B[i]
    dp[i+1][2] = dp[i][0] + C[i]

    dp[i+1][2] = dp[i][1] + C[i]
    dp[i+1][0] = dp[i][1] + A[i]

    dp[i+1][0] = dp[i][2] + A[i]
    dp[i+1][1] = dp[i][2] + B[i]
print(max(dp[N]))

Submission status: Wrong Answer

Solution code:
n = int(input())
f = list(map(int, input().split()))
M = max(f)
idx = f.index(M)
plan = [[idx, M]]
for i in range(1, n):
    li = list(map(int, input().split()))
    li = sorted(enumerate(li), key=lambda x: -x[1])
    if li[0][0] == plan[i - 1][0]:
        plan.append([li[1][0], plan[i - 1][1] + li[1][1]])
    else:
        plan.append([li[0][0], plan[i - 1][1] + li[0][1]])

print(plan[n - 1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
ans = [[0]*3 for _ in range(n)]

ans[0][0] = abc[0][0]
ans[0][1] = abc[0][1]
ans[0][2] = abc[0][2]

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

print(max(ans[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
ans = [0] * (n+1)
prev_num = n+1

for i in range(n):
    num = abc[i].index(max(abc[i]))
    if num != prev_num:
        ans[i+1] = ans[i] + max(abc[i])
        prev_num = abc[i].index(max(abc[i]))
    else:
        abc[i].pop(abc[i].index(max(abc[i])))
        ans[i+1] = ans[i] + max(abc[i])
        prev_num = abc[i].index(max(abc[i]))

print(ans[-1])

Submission status: Wrong Answer

Solution code:
from __future__ import division, print_function

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

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


# PyPy 2 Fast IO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Importing Modules
import math
import collections

from collections import Counter
from math import fabs

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[0,0,0]
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(3):
        x=a[j]
        b=a.copy()
        a.remove(x)
        dp[j]+=max(a)
        a=b.copy()
print(max(dp))

Submission status: Wrong Answer

Solution code:
n=int(input())
dp=[0,0,0]
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(3):
        x=a[j]
        b=a.copy()
        a.remove(x)
        dp[j]+=max(a)
        a=b.copy()
        
print(max(dp))

Submission status: Wrong Answer

Solution code:
n=int(input())
s1=s2=0
for i in range(n):
    a=list(map(int,input().split()))
    a.sort()
    if(i%2==0):
        s1+=a[1]
        s2+=a[2]
    else:
        s1+=a[2]
        s2+=a[1]
print(max(s1,s2))

Submission status: Wrong Answer

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

dp = [(None, 0)] * N
dp[0] = max(enumerate(ABC[0]), key=lambda x: x[1])

for i in range(1, N):
    for j in range(3):
        if j is not dp[i-1][0]:
            dp[i] = max(dp[i], (j, dp[i-1][1] + ABC[i][j]), key=lambda x: x[1])

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

Submission status: Wrong Answer

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[0][i], dp[1][i], dp[2][i])


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

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
arr = [list(map(int, sys.stdin.readline().split())) for i in range(n)]
 
dp = [[-1] * 3 for i in range(n)]
 
dp[0][0] = arr[0][0]
dp[0][1] = arr[0][1]
dp[0][2] = arr[0][2]
 
for i in range(1, n):
	dp[i][0] = max(dp[i - 1][1] + arr[i][0], dp[i - 1][2] + arr[i][0])
	dp[i][1] = max(dp[i - 1][0] + arr[i][1], dp[i - 1][2] + arr[i][1])
	dp[i][2] = max(dp[i - 1][0] + arr[i][2], dp[i - 1][1] + arr[i][2])

Submission status: Wrong Answer

Solution code:
def cmax(d):
  max_k, max_v = max(d.items(), key=lambda x: x[1])
  return dp[i-1] + max_v, max_k

n = int(input())

a = []
b = []
c = []

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

abc = {"a": a[0], "b": b[0], "c": c[0]}

dp = [0] * n
max_k, max_v = max(abc.items(), key=lambda x: x[1])

dp[0] = max_v
yesterday = max_k

for i in range(1, n, 1):
  if yesterday == "a":
    d = {"b": b[i], "c": c[i]}
    dp[i], yesterday = cmax(d)
  
  elif yesterday == "b":
    d = {"a": a[i], "c": c[i]}
    dp[i], yesterday = cmax(d)
    
  elif yesterday == "c":
    d = {"a": a[i], "b": b[i]}
    dp[i], yesterday = cmax(d)
    
print(dp[n-1])