Go: package main

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

var cache [100][100]int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	tables := []table{}
	for i := 0; i < num; i++ {
		sc.Scan()
		num1, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		num2, _ := strconv.Atoi(sc.Text())
		t := table{num1, num2}
		tables = append(tables, t)
	}

	fmt.Println(minimum(0, len(tables)-1, tables))
}

type table struct {
	v int
	h int
}

func minimum(i int, j int, t []table) int {
	if i == j {
		return 0
	}

	// fmt.Printf("i:%v j:%v\n", i, j)
	if cache[i][j] != 0 {
		return cache[i][j]
	}

	min := math.MaxInt64
	for k := i; k < j; k++ {
		p := t[i].v
		n := t[k].h
		q := t[j].h
		val := minimum(i, k, t) + minimum(k+1, j, t) + p*n*q
		if val < min {
			min = val
		}
	}

	cache[i][j] = min
	return min
}

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)