Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		fmt.Scan(&a[i+1])
	}

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

	for d := 2; d <= n; d++ {
		for s := 0; s+d <= n; s++ {
			min := 1 << 30
			for j := s+1; j < s+d; j++ {
				val := m[s][j] + m[j][s+d] + a[s]*a[j]*a[s+d]
				if val < min {
					min = val
				}
			}
			m[s][s+d] = min
		}
	}
	fmt.Println(m[0][n])
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin>>n;
    int m[n+1][n+1],p[n+1];
    rep(i,n){
        cin>>p[i]>>p[i+1];
        m[i][i]=0;
    }
    m[n][n]=0;
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            m[i][j]=1000000;
            for(int k=i;k<j;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;
}

C++: #include<iostream>

#define N 101

int n;
int a[N];
int g[N][N];

using namespace std;
int main() {

    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i]>>a[i+1];
    

    int i = 1, j = 1, k = 1, min, b;
    while(1) {
        if(i == 1 && j == n+1) break;
        if(i == j) g[i][j] = 0;
        
        if(i != j) {
            min = (1<<21);
            for(int x = i; x < j; x++) {
                b = g[i][x] + g[x+1][j] + a[i-1] * a[x] * a[j];
                if(min > b) min = b;
            }
        
            g[i][j] = min;
        }
        
        i++;
        j++;
        if(j > n) {
            i = 1;
            j = ++k;
        }
    }

    cout<<g[1][n]<<endl;

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX 105


int main(){
    int m[MAX][MAX];
    int p[MAX];
    int n;
    //FILE *fw=fopen("a.txt","r");
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d %d",&p[i],&p[i+1]);
    }
    //printf("start\n");
    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]*p[k+1]*p[j+1]);
            }
        }
    }
    printf("%d\n",m[1][n]);
    return 0;
}

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

static const int N = 100;

int main() {
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> p[i - 1] >> p[i];
	}
	
	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 = 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]);
			}
		}
	}
	
	cout << m[1][n] << endl;
	
	return 0;
}

C++: #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() { 
  int M[101][101];
  int P[100];
  rep(i,101){
    rep(j,101) M[i][j]=1e9;
  }
  
  int n;
  cin>>n;
  
  rep(i,n) 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=i+l-1;
      for(int k=i;k<j;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;
}

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

int main(){
  int n, p[101], m[101][101], i, j, k, l;
  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(l = 2;l <= n;l++){
    for(i = 1;i <= n - l + 1;i++){
      j = i + l - 1;
      m[i][j] = (1 << 21);
      for(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;
}

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

int min(int a, int b) { return a < b ? a : b; }

int main() {

    int n;
    cin >> n;
    int p[101] = {0};
    for (int i = 1; i <= n; ++i) {
        cin >> p[i - 1] >> p[i];
    }

    int m[101][101] = {0};
    for (int l = 2; l <= n; ++l) {
        for (int 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]);
            }
        }
    }

    cout << m[1][n] << endl;
    return 0;
}

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

int main()
{
	int n, i, j, l,k;
	int A[101];
	int q[101][101];
	cin >> n;
	for (i = 1; i < n+1; i++) {
		cin >> A[i - 1] >> A[i];
	}
	for (i = 0; i < n + 1; i++) q[i][i] = 0;

	for (l = 2; l < n + 1; l++) {
		for (i = 1; i < n - l + 2; i++) {
			j = i + l - 1;
			q[i][j] = (1<<21);
			for (k = i; k < j; k++) {
				q[i][j] = min(q[i][j], q[i][k] + q[k + 1][j] + A[i - 1] * A[k] * A[j]);
			}
		}
	}
	cout << q[1][n] << endl;

}

C++: #include <algorithm>
#include <cstdio>

using namespace std;

#define MAX_N (105)
#define MAX_R (105)
#define MAX_C (105)
#define INF (MAX_N * MAX_R * MAX_C)

int r[MAX_N];
int c[MAX_N];
int dp[MAX_N][MAX_N];
int n;

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	scanf("%d %d", &r[i], &c[i]);
    }
    
    for ( int l = 1; l <= n; l++ ) {
	for ( int h = 0; h <= n - l; h++ ) {
	    if ( l == 1 ) dp[h][h+l-1] = 0;
	    else {
		// (h~m), (m+1~h+l-1)
		int min_cost = INF;
		for ( int m = h; m < h + l - 1; m++ ) {
		    int cost = dp[h][m] + dp[m+1][h+l-1] + r[h] * c[m] * c[h+l-1];
		    min_cost = min( min_cost, cost );
		}
		dp[h][h+l-1] = min_cost;
	    }
	}
    }
    printf("%d\n", dp[0][n-1]);
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
ll INF=1000000007;

int main(){
    ll dp[110][110];
    ll n;
    cin >> n;
    ll r[n],c[n];
    rep(i,n) cin >> r[i] >> c[i];
    rep(i,n) dp[i][i]=0;
    for(ll m=1;m<=n-1;m++){
        rep(i,n-m){
            dp[i][i+m]=INF;
            for(ll k=i;k<=i+m-1;k++){
                if(dp[i][i+m]>dp[i][k]+dp[k+1][i+m]+r[i]*c[k]*c[i+m]){
                    dp[i][i+m] = dp[i][k]+dp[k+1][i+m]+r[i]*c[k]*c[i+m];
                }
            }
        }
    }
    cout << dp[0][n-1] << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define INFTY powl(2,60)

vector<vector<long long>> m(101,vector<long long>(101));
vector<int> p(101);

long long matrixChainMultiplication(int n){
    for(int i=1;i<n+1;i++){
        m[i][i]=0;
    }
    for(int l=1;l<n;l++){
        for(int i=1;i<n-l+1;i++){
            int j=i+l;
            m[i][j]=INFTY;
            for(int k=i;k<j;k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    return m[1][n];
}

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i]>>p[i+1];
    }
    cout<<matrixChainMultiplication(n)<<endl;
}