Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make([][]int, n)
	sizes := make([][]int, n)
	for i := 0; i < n; i++ {
		sizes[i] = []int{nextInt(), nextInt()}
		m[i] = make([]int, n)
	}
	// fmt.Println(sizes)

	for w := 1; w < n; w++ {
		for i := 0; i < n-w; i++ {
			j := i + w
			minBetweenIandJ := 10000000
			for k := i; k < j; k++ {
				// fmt.Println(i, j, k, m[i][k], m[k+1][j], sizes[i][0]*sizes[k][1]*sizes[j][1])
				minBetweenIandJ = min(minBetweenIandJ, m[i][k]+m[k+1][j]+sizes[i][0]*sizes[k][1]*sizes[j][1])
			}
			m[i][j] = minBetweenIandJ
		}
	}
	// for i := 0; i < len(m); i++ {
	// 	fmt.Println(stringifyArray(m[i]))
	// }
	fmt.Println(m[0][n-1])
}

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;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define N 100
int main(){
	int n,p[N+1],m[N+1][N+1];
	cin>>n;
	for(int i=0;i<n;i++)	cin>>p[i]>>p[i+1];
	for(int i=1;i<=n;i++)	m[i][i]=0;
	for(int l=2;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			int j=l+i-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]);
			}
		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}