Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

C++: #include<stdio.h>
#include<iostream>
//#include<queue>
#include<algorithm>
using namespace std;
static const int N = 100;

int main() {
	int i, n, m[N + 1][N + 1], p[N + 1];
	//priority_queue<int> PQ;

	scanf("%d", &n);

	for (i = 1; i <= n; i++)scanf("%d %d", &p[i - 1], &p[i]);

	for (i = 1; i <= n; i++) {
		m[i][i] = 0;
	}

	for (int l = 2; l <= n; l++) {
		for (i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k <= j - 1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}

	printf("%d\n", m[1][n]);

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;

vector<vector<int> > cost,best;
vector<int> A;

void compute(int s,int e){
	int minc = 0;
	int mink = -1;
	for(int k=s+1;k<=e;++k){
		if (cost[s][k-1] < 0){
			compute(s,k-1);
		}
		if (cost[k][e] < 0) {
			compute(k,e);
		}
		int c = cost[s][k-1] + A[s]*A[k]*A[e+1] + cost[k][e];
		if (mink < 0 || c < minc) {
			minc = c;
			mink = k;
		}
	}
	cost[s][e] = minc;
	best[s][e] = mink;
}

int main(){
	int n;
	cin >> n;
	A.resize(n+1);
	for(int i=0;i<n;++i) {
		int r,c;
		cin >> r >> c;
		if (i==0){
			A[0] = r;
		}
		if (A[i] != r){ cout << "error";exit(0);}
		A[i+1] = c;
	}
	cost.resize(n);
	best.resize(n);
	for(int i=0;i<n;++i){
		cost[i].resize(n);
		best[i].resize(n);
		for(unsigned j=0;j<cost[i].size();++j){
			cost[i][j] = -1;
			best[i][j] = -1;
		}
		cost[i][i]=0;
		best[i][i]=i;
	}
	compute(0,n-1);
	cout << cost[0][n-1] << std::endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  int n; cin >> n;
  vector<int> p(n+1, 0);
  rep(i, n) cin >> p[i] >> p[i+1];
  vector<vector<ll>> dp(n+1, vector<ll>(n+1, inf));
  rep(i, n+1) dp[i][i] = 0;
  rep(i, n) dp[i][i+1] = 0;
  for (int len=2; len<=n; len++) {
    for (int left=0; left+len<=n; left++) {
      int right = left+len;
      dp[left][right] = inf;
      for (int i=left+1; i<right; i++) {
        dp[left][right] = min(dp[left][right], dp[left][i] + dp[i][right] + p[left]*p[i]*p[right]);
      }
    }
  }
  cout << dp[0][n] << endl;

  return 0;
}

C++: #include<iostream>
using namespace std;
#define M 101
#define I 100000000
int main(){
    int n,p[M],m[M][M],i,j,k,t;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>p[i-1]>>p[i];
    }
    for(i=1;i<=n;i++)m[i][i]=0;
    for(i=2;i<=n;i++){
        for(j=1;j<=n-i+1;j++){
            t=i+j-1;
            m[j][t]=I;
            for(k=j;k<=t-1;k++){
                m[j][t]=min(m[j][t],m[j][k]+m[k+1][t]+p[j-1]*p[k]*p[t]);
            }
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int MAX_N = 100;

struct matrix {
    int r;
    int c;
};

ll dp[MAX_N + 1][MAX_N + 1];

ll solve(const int i, const int j, const vector<struct matrix> &matrices) {
    if (j <= i) return 0;
    if (j - i == 1) return matrices[i].r * matrices[i].c * matrices[j].c;
    if (dp[i][j] != LONG_LONG_MAX / 2) return dp[i][j];

    ll answer = LONG_LONG_MAX / 2;
    for (int k = i; k < j; k++) {
        chmin(answer, solve(i, k, matrices) + solve(k + 1, j, matrices) + matrices[i].r * matrices[k].c * matrices[j].c);
    }

    dp[i][j] = answer;
    return answer;

    // for (int i = 1; i <= N; i++) {
    //     int j = i + 1;
    //     dp[i][j] = matrices[i].r * matrices[i].c * matrices[j].c;
    //     j++;
    //     for (; j <= N; j++) {
    //         for (int k = i + 1; k < j; k++) {
    //             chmin(dp[i][j], dp[i][k] + dp[k + 1][j] +
    //                     matrices[i].r * matrices[k].c * matrices[j].c);
    //         }
    //     }
    // }
    // 
    // return dp[1][N];
}

int main(void) {
    int N;
    cin >> N;
    vector<struct matrix> matrices(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> matrices[i].r >> matrices[i].c;
    }

    for (int i = 1; i <= MAX_N; i++) {
        for (int j = i + 1; j <= MAX_N; j++) {
            dp[i][j] = LONG_LONG_MAX / 2;
        }
    }

    cout << solve(1, N, matrices) << endl;

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    
    return 0;
}

C++: #include <cstdio>

#define N 10000

typedef long long int lli;

lli a[N*N];
lli b[N*N];
lli c[N*N];

int n,m,l;

void mult() {
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            for(int k=0; k<m; k++)
                c[i*N + j] += a[i*N + k] * b[k*N + j];
}

int main(void) {
    scanf("%d%d%d",&n,&m,&l);

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            scanf("%lld", &a[i*N + j]);
    for(int i=0; i<m; i++)
        for(int j=0; j<l; j++)
            scanf("%lld", &b[i*N + j]);
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            c[i*N + j] = 0;

    mult();

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<l-1; j++)
            printf("%lld ", c[i*N + j]);
        printf("%lld", c[i*N + l-1]);
        printf("\n");
    }
    return 0;
}