Go: package main

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

const N = 100

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

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var p [N]int
	var m [N + 1][N + 1]int
	for i := 1; i <= n; i++ {
		sc.Scan()
		p[i-1], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

	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])
			}
		}
	}

	return fmt.Sprintf("%d", m[1][n])
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, in;
	vector<ll> v;
	cin >> n;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
		cin >> in;
		if (i == n - 1)v.push_back(in);
	}
	vector<vector<ll>> vv(n, vector<ll>(n));
	for (int i = 1; i < n; i++) {
		vv[i - 1][i] = v[i - 1] * v[i] * v[i + 1];
	}
	for (int i = 2; i < n; i++) {
		for (int j = 0; i+j < n; j++) {
			ll ans;
			for (int k = 0; k <= i - 1; k++) {
				if (k == 0) {
					ans = vv[j][j + k] + vv[j + k+1][j + i] + v[j] * v[j + k + 1] * v[i + j + 1];
				}
				else {
					ll tmp = vv[j][j + k] + vv[j + k+1][j + i] + v[j] * v[j + k + 1] * v[i + j + 1];
					if (ans > tmp)ans = tmp;
				}
			}
			vv[j][i + j] = ans;
		}
	}
	cout << vv[0][n - 1] << endl;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define MAX 100


int P[MAX+1];
int n,j;
int m[MAX+1][MAX+1];
void matrix(){
  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++){
      j=i+l-1;
      m[i][j]=(1<<21);
      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;
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>P[i-1]>>P[i];
    //printf("%d\n", P[i-1]);
  }
  matrix();

}

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

int main(){
  int n,p[101],m[101][101];
  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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
pii A[200];//firstは行secondを列とする
int dp[200][200];//dp[i][j]:=Ai...Ajの最小スカラー積とする
int n;
int f[200][200];//最適な括弧を挿入する位置
void solve(){
	for(int i =0;i < n;i++){
		for(int j =0;j < n;j++){
			if(i==j)dp[i][j]=0;
			else dp[i][j]=INF;
		}
	}
	
	for(int k =1;k <n;k++){//鎖の数
		for(int i =0;i <n-k;i++){//どこから始めるか
			for(int j =i;j <i+k;j++){//どこに括弧を挟むか
				int tmp =A[i].first*A[j].second*A[i+k].second;
				if(dp[i][i+k] >dp[i][j]+dp[j+1][i+k]+tmp){
					dp[i][i+k]=dp[i][j]+dp[j+1][i+k]+tmp;
					f[i][i+k] =j;
				}
			}
		}
	}
}

void print(int i,int j){//解を表示する
	if(i==j){
		cout <<"A"<<i;
	}else{
		cout <<"(";
		         print(i,f[i][j]);
		         print(f[i][j]+1,j);
		         cout <<")";
}
}


int main(){
	cin>>n;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i =0;i < n;i++){
		cin>>A[i].first>>A[i].second;
	}
	solve();
	cout <<dp[0][n-1]<<endl;
	//print(0,n-1);
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 110
#define INF (int)(2<<29)

int main(){
	int n, r, c, m[MAX][MAX] = {}, p[MAX];
	
	cin>>n;
	
	for(int i = 1; i <= n; i++){
		cin>>r>>c;
		p[i-1] = r;
		p[i] = c;
	}
	for(int l = 2; l <= n; l++){
		for(int i = 1; i <= n-l+1; i++){
			int j = i + l - 1;
			m[i][j] = INF;
			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]);
			}
		}
	}
	// for(int i = 0; i <= n; i++){
		// for(int j = 0; j <= n; j++){
			// printf("%12d", m[i][j]);
		// }cout<<endl;
	// }
	
	cout<<m[1][n]<<endl;
	
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPE(i, n) for (int i = 0; i <= (n); ++i)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

typedef long long ll; //64bit型
using namespace std;

const long long INF = 1LL << 60; //無限大の値
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>

#define int             long long
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

int dp[101][101];

signed main(){
    int N; cin >> N;
    vector<int> p( N + 1 );
    REP( i, N ){
        cin >> p[i] >> p[i + 1];
    }

    for( int l = 2; l <= N; l++ ){
        for( int i = 1; i <= N - l + 1; i++ ){
            int j = i + l - 1;
            dp[i][j] = INF;
            for( int k = i; k <= j - 1; k++ ){
                dp[i][j] = min( dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[j] * p[k] );
            }
        }
    }

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