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++: #define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int n; std::cin >> n;
    std::vector<int> r(n), c(n);
    for(int i(0); i < n; ++i) std::cin >> r[i] >> c[i];
    //dp[i][j] := iからjまでの計算に必要な回数
    std::vector<std::vector<int>> dp(n, std::vector<int>(n, 0));
    for(int d(1); d < n; ++d){
        for(int i(0), i_len(n - d); i < i_len; ++i){
            int j(i + d);
            dp[i][j] = INF;
            for(int k(i); k < j; ++k){
                chmin(dp[i][j], dp[i][k] + dp[k+1][j] + r[i]*c[k]*c[j]);
            }
        }
    }
    std::cout << dp[0][n-1] << std::endl;
    return 0;
}

C++: // ALDS 1_10_B
#include<cstdio>
#include<cstring>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )
#define repi(i,a,b) for( int i = (a); i != (b); ++i )

const int INF = 1<<28;

int n;
std::vector<int> r(100);
std::vector<std::vector<int> > dp( 100, std::vector<int>( 100, INF ) );

int main()
{
	scanf( "%d", &n );
	rep( i, n )
		scanf( "%d%d", &r[i], &r[i+1] );

	rep( i, n )
		dp[i][i] = 0;

	repi( k, 1, n ) rep( i, n-k ) repi( j, i, i+k )
		dp[i][i+k] = std::min( dp[i][i+k], dp[i][j]+dp[j+1][i+k]+r[i]*r[j+1]*r[i+k+1] );	

	printf( "%d\n", dp[0][n-1] );

	return 0;
}

C++: #include <iostream>
#include <limits>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        int r, c;
        cin >> r >> c;
        v.emplace_back(r, c);
    }

    vector<vector<int>> dp(n, vector<int>(n, numeric_limits<int>::max()));

    for (int i = 0; i < n; ++i) {
        dp[i][i] = 0;
    }

    auto cost = [&v](int i, int k, int j) {
        return v[i].first * v[k].second * v[j].second;
    };

    // auto p = [&dp, n] {
    //    for (int i = 0; i < n; ++i) {
    //        for (int j = 0; j < n; ++j) {
    //            cout << dp[i][j] << ' ';
    //        }
    //        cout << endl;
    //    }
    //    cout << endl;
    //};
    for (int l = 2; l <= n; ++l) {
        for (int i = 0; i < n - l + 1; ++i) {
            int j = i + l - 1;
            for (int k = i; k < j; ++k) {
                dp[i][j] =
                    min(dp[i][j], dp[i][k] + dp[k + 1][j] + cost(i, k, j));
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

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

#define INF 100000001

using namespace std;

int DP[101][101];
int *p;

int rec(int r, int c){
  int Min = INF;
  int num = c-r;

  for (int i = 0; i < num; i++){
    Min = min(Min, DP[r][r+i] + DP[r+i+1][c] + p[r-1]*p[r+i]*p[c]);
  }
  return Min;
}
  int main(){
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) DP[i][i] = 0;

    p = (int *)malloc(sizeof(int)*(N+1));

    cin >> p[0];
    cin >> p[1];
      int bb;
    for(int i = 2; i <= N; i++){
      cin >> bb;
      cin >> p[i];
    }

    for(int i = 1; i < N; i++) DP[i][i+1] = p[i-1]*p[i]*p[i+1];

    for(int j = 0; j <= N-3; j++){
      for(int i = 3+j; i <= N; i++){
	DP[i-2-j][i] = rec(i-2-j,i);
      }
    }

    cout << DP[1][N] << endl;

    return 0;
  }

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

static const int N = 100;

int main()
{
	int n;
	int p[N + 1];
	int 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 << 27);
			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;

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; 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,p[105],m[105][105];
  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;
}

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

static const int N = 100;

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