# ---------- Import ----------
import sys
input = sys.stdin.readline

# ---------- Declaration ----------
R, G, B = 0, 1, 2

# ---------- Main ----------
N = int(input())
RGB_list = []

for _ in range(N):
    RGB_list.append(list(map(int, input().split())))
    
for i in range(1, N):
    RGB_list[i][R] = min(RGB_list[i-1][G], RGB_list[i-1][B]) + RGB_list[i][R]
    RGB_list[i][G] = min(RGB_list[i-1][R], RGB_list[i-1][B]) + RGB_list[i][G]
    RGB_list[i][B] = min(RGB_list[i-1][R], RGB_list[i-1][G]) + RGB_list[i][B]

print(min(RGB_list[N-1]))

# ---------- Comment ----------
# N번땅에서 N+1번땅을 고려하는 것이 아닌, N번땅에서 N-1번땅을 고려하기.
# R, G, B 각각 지역에서 시작하는 경우를 구하고, 가장 작은 값 출력하기.

+ Recent posts