Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	mm := make([]int, n+1)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		mm[i] = getNextInt(scanner)
		mm[i+1] = getNextInt(scanner)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			for k := i; k <= j-1; k++ {
				d := dp[i][k] + dp[k+1][j] + mm[i-1]*mm[k]*mm[j]
				if dp[i][j] == 0 || dp[i][j] > d {
					dp[i][j] = d
				}
			}
		}
	}

	fmt.Fprintln(writer, dp[1][n])

	writer.Flush()
}

Python: # 連鎖行列積 Matrix chain multiplication

n = int(input())
p = [-1 for i in range(n + 1)]
M = [[-1 for i in range(n + 1)] for i in range(n + 1)]

for i in range(1, n + 1):
    l, m = (int(i) for i in input().split())
    p[i - 1] = l
    p[i] = 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] = 2000000000
        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])

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def mat_mul_opt(_mat_info):
    rc_info = list(map(int, _mat_info[0]))
    rc_info.extend(list(map(lambda x: int(x[1]), _mat_info[1:])))

    for l in range(2, mat_num + 1):
        for i in range(1, mat_num - l + 2):
            j = i + l - 1
            ans[i][j] = 1e7
            for k in range(i, j):
                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k + 1][j] +
                                rc_info[i - 1] * rc_info[k] * rc_info[j])

    return ans[1][mat_num]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    mat_num = int(_input[0])
    mat_info = tuple(map(lambda x: x.split(), _input[1:]))
    # assert len(mat_info) == mat_num

    ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
    print(mat_mul_opt(mat_info))

Python: n = int(input())
p = [0]*(n+1)

INF = 1000000000

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

dp = [[-1]*(n+2) for _ in range(n+2)]

def DFS(i,j):
    if dp[i][j] != -1:
        return dp[i][j]
    else:
        if j-i == 2:
            dp[i][j] = p[i]*p[i+1]*p[i+2]
            return dp[i][j]
        elif j-i == 1:
            dp[i][j] = 0
            return 0
        else:
            calculation_amount = INF
            for k in range(i+1,j):
                tmp = DFS(i,k) + DFS(k,j) + p[i]*p[j]*p[k] 
                calculation_amount = min(calculation_amount,tmp)
            dp[i][j] = calculation_amount
            return calculation_amount

print(DFS(0,n))

Python: n = int(input())
data = list(list(map(int, input().split())) for _ in range(n))
m = [[None for _ in range(n+1)]for _ in range(n+1)]
p = []
INF = 1000000000

for i in range(1, n+1):
    m[i][i] = 0

p.append(data[0][0])
for i in range(n):
    p.append(data[i][1])

for l in range(2, n+1):
    for i in range(1, n - l + 2):
        j = i + l - 1
        m[i][j] = 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(p)
#print(data)
print(m[1][n])

Python: n = int(input())
p = [0] * (n + 1)
for i in range(1, n + 1):
    r, c = [int(v) for v in input().split()]
    p[i-1] = r
    p[i] = c

N_MAX = 100
M_MAX = 1 << 21
m = [[-1] * (n+1) for i in range(n+1)]

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] = M_MAX
        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])

Python: def s():
 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 i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if 1>m[r][c]or m[r][c]>x:m[r][c]=x
 print(m[r][c])
s()

Python: def matrix_chain_order(p):
    n = len(p)
    m = {}
    for length in range(1, n + 1):
        for i in range(n - length + 1):
            j = i + length - 1
            if i == j:
                m[(i, j)] = 0
            else:
                q = None
                for k in range(i, j):
                    c = m[(i, k)] + m[(k+1, j)] + p[i][0] * p[k][1] * p[j][1]
                    if q is None or c < q:
                        q = c
                m[(i, j)] = q
    return m[(0, n-1)]

if __name__ == '__main__':
    import sys

    p = []
    n = int(input())
    for _ in range(n):
        p.append(tuple(map(int, sys.stdin.readline().split())))
    print(matrix_chain_order(p))

Python: n = int(input())
INF = 10**9
P = [list(map(int, input().split())) for i in range(n)]
m = [[0]*n for i in range(n)]

for l in range(2, n + 1):
    for i in range(n - l + 1):
        j = i + l - 1
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + P[i - 1][0] * P[k][1] * P[j][1])

print(m[0][n - 1])

Python: n = int(input())
INF = 10**9
P = []
for i in range(n):
    p = map(int, input().split())
    P.append()
m = [[0]*n for i in range(n)]

for l in range(2, n + 1):
    for i in range(n - l + 1):
        j = i + l - 1
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + P[i - 1][0] * P[k][1] * P[j][1])

print(m[0][n - 1])

Python: import sys
n=int(input())+1
e=list(map(lambda x:x.split(),sys.stdin))
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: inf = 10**9+7
mod = 10**9+7
n = int(input())
rc = [list(map(int, input().split())) for i in range(n)]
dp = [[inf for j in range(n)]for i in range(n)]
for i in range(n):
    dp[i][i] = 0
for k in range(1,n):
    for i in range(0,n-k):
        for j in range(k):
            dp[i][i+k] = min(dp[i][i+k], dp[i][i+j] + dp[i+j+1][i+k] + rc[i][0]*rc[i+j][1]*rc[i+k][1])
print(dp[0][n-1])

Python: def matrix_chain_multiplication(n):
    m = [[0 for x in range(n+1)] for y in range(n+1)]
    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(n):
    listed_input = input().split()
    p.append(int(listed_input[0]))

p.append(int(listed_input[1]))

matrix_chain_multiplication(n)

Python: def s():
 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 i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if not 0<m[r][c]<=x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()