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++: #define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	vector<int> p(n + 1);
	int i = 0;
	while (true)
	{
		cin >> p[i] >> p[i + 1];
		i++;
		if (i == n) break;
	}

	vector<vector<int>> m(n, vector<int>(n, INT_MAX));
	for (int i = 0; i < n; i++)
	{
		m[i][i] = 0;
	}

	for (int l = 1; l < n; l++)
	{
		for (int i = 0; i < n - l; i++)
		{
			int j = i + l;
			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]);
			}
		}
	}

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

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

int N = 100;

int main(){
  int i,j,k,l;
  int n,p[N+1],m[N+1];
  cin >> n;
  for(i = 1; i <= n; i++){
    cin >> p[i-1];
    cin >> p[i];
  }
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
  for(j = 2; j <= n; j++){
    for(i = 1; i <= n-j+1;i++){
      k = i+j-1;
      m[i][k] = (1 << 21);
      for(l = i; l <= j-1; l++){
        m[i][k] =min(m[i][k],m[i][l]+m[i][l]+m[k+1][i-1]*p[k]p[j]);
      }
    }
  }
cout << m[1][n] << endl;
return 0;
}

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

const long N = 100;

int main(){
	long n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (long i = 1; i <= n; i++){
		cin >> p[i - 1] >> p[i];
	}

	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long k = 0; 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 <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vvll dp(n, vll(n, INF));

  vll p(n + 1);
  rep(i, n) {
    cin >> p[i] >> p[i + 1];
    dp[i][i] = 0;
  }

  for (ll h = 1; h <= n - 1; h++) {
    for (ll i = 0; i <= n - 1 - h; i++) {
      ll j = i + h;
      for (ll k = i; k <= j - 1; k++) {
        chmin(dp[i][j], dp[i][k] + dp[k+1][j] + p[i] * p[k + 1] * p[j + 1]);
      }  // k
    }    // i
  }      // h

  cout << dp[0][n - 1] << endl;

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	vector<int> v(n + 1);
	for(int i = 0; i < n; i++) {
		int a,b;cin>>a>>b;
		v[i] = a;
		if (i == n - 1){
			v[i + 1] = b;
		}
	}
	vector<vector<int>> dp(n,vector<int>(n,INF));
	for(int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}

	for(int l = 1; l < n; l++) {//連鎖の大きさ(iとｊの幅)(j - i)
		for(int i = 0; i < n - l; i++) {
			int j = i + l;
			for(int k = i; k < j; k++) {
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k + 1][j] + v[i] * v[k + 1] * v[j + 1]);
			}
		}
	}
	cout << dp[0][n - 1] << 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<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][j]=0;
  for(int l=2;i<=n;i++){
    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 <bits/stdc++.h>
#define index indexxx
using namespace std;
int n;
int p[10000],m[1000][1000];
int index;
int fun(int left,int right)
{
	if(m[left][right]!=0)
		return m[left][right]; 
	if(left==right){
		return 0;
	}
	int i=left,j=right;
	int u=fun(left,left)+fun(left+1,right)+p[i-1]*p[i]*p[j];
	for(int k=i+1;k<j;k++){//遍历
		int t=fun(i,k)+fun(k+1,right)+p[i-1]*p[k]*p[j]; 
		if(t<u)
		{
			u=t;
		}
	}
	m[left][right]=u;
	return u;
}

int main(void)
{
	cin>>n;
	scanf("%d",p+(index++));
	scanf("%d",p+(index++));
	int tmp,x;
	for(int i=1;i<n;i++){
		scanf("%d",&x);
		scanf("%d",p+(index++));
	}
	printf("%d\n",fun(1,n));
	return 0;
}