DP 3-6
# p = int(input())
# x = []
# l = r = 0
# while p != 0:
# x.append(p%10)
# p //= 10
# for i in range(len(x) // 2):
# l += x[i]
# r += x[-(i + 1)]
# if len(x)%2 == 1:
# r += x[len(x)//2]
# m = 0
# def f(l,r):
# global x,m
# # print(l,r,x)
# q = len(x)
# c =0
# if len(x) % 2 == 1:
# r -= x[-1]
# q -= 1
# c = 1
# for i in range(q//2):
# if l == r:
# if q - i * 2 > m:
# print(x, i * 2, l, r)
# return q - (i * 2)
# l -= x[(q-i*2)//2-1]
# r -= (x[-i*2+c] + x[-(i*2)+1+c])
# return -1
# for i in range(len(x)):
# v = f(l,r)
# if v > m:
# m = v
# l -= x[0]
# x.pop(0)
# if len(x)%2==0 and len(x) != 0:
# l += x[len(x)//2-1]
# r -= x[len(x)//2-1]
# print(m)
cost = [[1,2,3,1],[5,4,2,5],[2,1,6,3],[1,7,6,7]]
memo = [[0 for j in range(4)] for i in range(4)]
def min(a,b):
if a > b:
return b
else:
return a
def mp(c):
global memo,cost
memo[0][0] = cost[0][0]
for i in range(1,4):
memo[0][i] = memo[0][i-1] + cost[0][i]
for i in range(1,4):
memo[i][0] = memo[i-1][0] + cost[i][0]
for i in range(1,4):
for j in range(1,4):
memo[i][j] = min(memo[i][j-1],memo[i-1][j]) + cost[i][j]
mp(0)
print(memo)




