Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	var n int
	var M [101][101]int

	n = nextInt()

	P := make([]int, n*2)

	for i := 1; i <= n; i++ {
		P[i-1] = nextInt()
		P[i] = nextInt()
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			M[i][j] = 1000000
			for k := i; k <= j-1; k++ {
				M[i][j] = int(math.Min(float64(M[i][j]), float64(M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j])))
			}
		}
	}
	fmt.Println(M[1][n])
}

Python: N = int(input())
m = []
for i in range(N):
  x,y = map(int,input().split())
  m.append((x,y))

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

for L in range(1,N): 
  for i in range(N-L): 
    j = i+L
    dp[i][j] = float('inf')
    for k in range(i,j):
      m0,m1,m2 = m[i],m[k],m[j]
      # print(i,j,k,m0,m1,m2)
      dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+m0[0]*m1[1]*m2[1])

print(dp[0][-1])

Python: import sys

# sys.stdin = open('input.txt')

N = 100 + 1

p = [0] * N
m = [[0] * N for _ in range(N)]

n = int(input())

for i in range(1, n+1):
    p[i-1], p[i] = map(int, input().split())
for i in range(1, n+1):
    m[i][i] = 0

for l in range(2, n+1):
    for i in range(1, n-l+1+1):
        j = i + l - 1
        m[i][j] = (1 << 21)
        for k in range(i, j-1+1):
            m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j])

print(m[1][n])

Python: def main():
    n = int(input())
    m1 = input().split()
    ps = [int(m1[0]), int(m1[1])]
    for _ in range(n - 1):
        ps.append(int(input().split()[1]))
    ms = [[float("inf") for _ in range(n)] for __ in range(n)]
    # 範囲 0 - n
    for i in range(n):
        ms[i][i] = 0

    for length in range(1, n):
        # 00 11 22 33 44 ...         nn
        # 01 12 23 34 45 ...      n-1,n
        # 02 13 24 35 46 ... n-2,n
        # ...
        # 0n
        for start in range(0, n - length):
            end = start + length
            # 仕切りpartition
            m_start_end = float("inf")
            for partition in range(start, end):
                m_start_end = min(m_start_end, ms[start][partition] + ms[partition + 1]
                                  [end] + ps[start] * ps[partition + 1] * ps[end + 1])
            ms[start][end] = m_start_end
    print(ms[0][n - 1])


if __name__ == "__main__":
    main()

Python: n=int(input())+1
e=[input().split()for _  in[0]*~-n]
p=[int(e[0][0])]+list(int(x[1])for x in e)
m=[[0]*n for _ in[0]*n]
for l in range(2,n):
 for i in range(1,n-l+1):
  j=i+l-1;m[i][j]=1e6
  for k in range(i,j):m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
print(m[1][n-1])

Python: import sys
INF = float("inf")
n = int(input())
m = [[0] * (n + 1) for _ in range(n + 1)]
li = [list(map(int, a.split())) for a in sys.stdin]
z = (li[0][0], ) + list(zip(*li))[1]
for l in range(1, n):
    for i in range(1, n - l + 1):
        j = i + l
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])
print(m[1][n])

Python: n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))

dp = [0 for _ in range(n)]
for i in range(n-1):
    dp[i] = data[i][0] * data[i][1] * data[i+1][1]



def mul(i, j):
    if i == j:
        return 0
    elif i == j - 1:
        return dp[i]
    num = 100000
    for k in range(i, j):
        num = min(num, mul(i, k) + mul(k+1, j) + data[i][0] * data[k][1] * data[j][1])
    return num

print(mul(0, n-1))

Python: INF = 1145141919810364364334

n = int(input())
p = []
for i in range(n):
    a,b = map(int,input().split())
    if i==0:
        p.append(a)
        p.append(b)
    else:
        p.append(b)
    
cost = [[INF] * (n+1) for i in range(n+1)]
for i in range(n+1):
    cost[i][i] = 0
    
for l in range(2,n+1):
    for i in range(1,n-l+2):
        j = i+l-1
        for k in range(i,j):
            cost[i][j] = min(cost[i][j] , cost[i][k] + cost[k+1][j] + p[i-1]*p[k]*p[j])
            
print(cost[1][n])

Python: import sys
from typing import List


if __name__ == "__main__":
    num_matrix = int(input())
    matrices: List[List[int]] = []
    for _ in range(num_matrix):
        matrices.append(list(map(lambda x: int(x), input().split())))
    dp = [[sys.maxsize] * num_matrix for i in range(num_matrix)]
    for i in range(num_matrix):
        dp[i][i] = 0

    for l in range(1, num_matrix):
        for i in range(num_matrix - l):
            row = matrices[i][0]
            col = matrices[i + l][1]
            dp[i][i + l] = min(row * matrices[j][1] * col + dp[i][j] + dp[j + 1][i + l]
                               for j in range(i, i + l))

    print(f"{dp[0][num_matrix - 1]}")

Python: import sys
def calc(i,j):
    if i == j:
        return 0
    elif j-i == 1:
        return A[i][0]*A[i][1]*A[j][1]
    else:
        if d[i][j]:
            return d[i][j]
        else:
            ret = sys.maxsize
            for k in range(i,j):
                tmp = calc(i,k)+calc(k+1,j)+A[i][0]*A[k][1]*A[j][1]
                if tmp < ret:
                    ret = tmp
            d[i][j] = ret
            return ret

n = int(input())
A = []
d = [[None for _ in range(n)] for _ in range(n)]
for i in range(n):
    a,b = [int(i) for i in input().split()]
    A.append((a,b))
print(calc(0,n-1))

Python: n = int(input())
p=[]
for i in range(n):
    s,c = map(int,input().split())
    if i == 0:
        p.append(s)
    p.append(c)


m = [[0 for _ in range(n+1)] for _ in range(n+1)]

for j in range(1, n):
    for i in range(1, n+1):
        if i+j > n:
            break
        if i != i+j:
            m[i][i+j] = min([m[i][k] + m[k+1][i+j] + p[i+j]*p[k]*p[i-1] for k in range(i,i+j)])

print(m[1][n])

Python: import sys
input = sys.stdin.readline

def matrixChainMultiplication(n):
    for l in range(2, n+1):
        for i in range(1, n-l+2):
            j = i + l - 1
            min_ = 2**21 # 十分大きい数
            for k in range(i, j):
                value = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]
                if min_ > value:
                    min_ = value
            m[i][j] = min_

m = [[0]*(101) for _ in range(101)]
p = [0] * 101
N = int(input())
l0 = list(map(int, input().split()))
p[0] = l0[0]
p[1] = l0[1]
for _ in range(1, N):
    li = list(map(int, input().split()))
    p[_+1] = li[1]
matrixChainMultiplication(N)
print(m[1][N])

Python: def chain(p,n):
    m={}
    for i in range(1,n+1):
        m[i] = {i:0}
        
    for l in range(2,n+1):
        for i in range(1,n-l+2):
            j = i + l -1
            m[i][j] = float("inf")
            for k in range(i,j):
                m[i][j] = min(m[i][j],m[i][k]+m[k+1][j] + p[i-1]*p[k]*p[j])
    print(m[1][n])

p={}
n = int(input())
for i in range(1,n+1):
    st = input()
    w = st.split()
    p[i-1] = int(w[0])
    p[i]   = int(w[1])
chain(p,n)