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 <iostream>
#include <algorithm>
using namespace std;

static const int N = 100;

int main() {

	int n, p[N + 1], m[N + 1][N + 1];

	scanf("%d", &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]);
				}
			}
		}

		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++: #include <bits/stdc++.h>

using namespace std;

int main() {
    int n; 
    cin >> n; 
    int r, c;
    vector<pair<int, int>> v; 
    vector<int> dims; 
    for (int i = 0; i < n; ++i) { 
            cin >> r >> c; 
            if (i == 0) { 
                dims.push_back(r);
            } 
        dims.push_back(c);
    }
    // for (int i = 0; i < dims.size(); ++i)
    //     cout << dims[i] << " ";
    int dp[n][n];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            dp[i][j] = 0;
    
    for (int len = 2; len <= n; ++len) { 
        for (int i = 0; i <= n - len; ++i) { 
            int j = i + len-1;
            // cout << i << " " << j <<" -> ";
            dp[i][j] = INT_MAX;
            for (int k = i; k < j; ++k) { 
                // cout << dp[i][k] << " " << dims[i] << " " << dims[k+1] << " " << dims[j+1] << endl;
               int q = dp[i][k] + dp[k+1][j] + dims[i]*dims[k+1]*dims[j+1]; 
               dp[i][j] = min(q, dp[i][j]);
            }
        }
    }
    // for (int i = 0; i < n; ++i) {
    //     for (int j = 0;j < n; ++j)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    cout << dp[0][n-1] << endl;
   
}

C++: #include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

#define MAX 100005
#define INF INT_MAX

typedef long long ll;
typedef pair<int, int> P;

P a[MAX];
map<P, int> memo;

int minMultTime(int s, int e)
{
    if (s >= e) return 0;
    if (memo[P(s,e)]) return memo[P(s,e)];

    int ans = INF;
    rep(i,e-s) {
        int m1 = minMultTime(s,s+i);
        int m2 = minMultTime(s+i+1,e);
        int m3 = a[s].first * a[s+i].second * a[e].second;
        ans = min(ans, m1+m2+m3);
    }
    memo[P(s,e)] = ans;

    return ans;
}

int main(int, char**)
{
    int n;
    cin >> n;

    rep(i,n) {
        cin >> a[i].first;
        cin >> a[i].second;
    }

    cout << minMultTime(0, n-1) << endl;

    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000000
typedef long long ll;
using namespace std;

int main()
{
	ll n;
	cin >> n;
	vector<ll> M(n + 1);
	cin >> M[0];
	for (int i = 1; i < n; i++) {
		cin >> M[i] >> M[i];
	}
	cin >> M[n];
	vector<vector<ll>> dp(n, vector<ll>(n, INF));
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}
	for (ll k = 1; k < n; k++) {
		for (ll i = 0; i + k < n; i++) {
			for (ll j = 0; j <= i + k - 1; j++) {
				ll cost = dp[i][j] + dp[j + 1][i + k] + M[i] * M[j + 1] * M[i + k + 1];
				if (cost < dp[i][i + k]) {
					dp[i][i + k] = cost;
				}
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#include <cmath>

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
const double PI = 3.14159265358979323846;

typedef pair<ll, ll> P;


string to_upper(string str) {
    int diff = 'a' - 'A';
    for (int i = 0; i < str.size(); i++) {
        char c = str[i];
        if ('A' <= c && c <= 'Z') {
            c += diff;
            str[i] = c;
        }
    }
    return str;
}


int main() {

    int n;
    cin >> n;


    vector<P> matrix_list(n);
    rep(i, n) cin >> matrix_list[i].first >> matrix_list[i].second;

    vector<ll> p(n + 1, 0);
    p[0] = matrix_list.front().first;
    rep(i, n) p[i + 1] = matrix_list[i].second;

    vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, 0));


    for (int l = 2; l <= n; l++) {  // 行列の個数
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            ll min_cost = INF;
            for (int k = i; k < j; k++) {
                if (k == i) min_cost = dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j];
                else min_cost = min(min_cost, dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
            dp[i][j] = min_cost;
        }
    }

    cout << dp[1][n] << endl;
}