Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 1; i <= m; i++)c[i][0] = 0;
	for (int j = 1; j <= n; j++)c[0][j] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (X[i] == Y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}
		return maxl;
}

	int main() {
		string s1, s2;
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> s1 >> s2;
			cout << lcs(s1, s2) << endl;
		}

		return 0;
	}

C++: #include<stdio.h>

#define N 106
#define INF 100000000

int P[N];
int m[N][N];


int matrixchainorder(int*,int);

int main(){
  int i;
  int num;

  scanf("%d",&num);
  

  for(i=1;i<=num;i++){
    //printf("%d\n",i);
    scanf("%d%d",&P[i-1],&P[i]);
  }
  
  printf("%d\n",matrixchainorder(P,num));

  return 0;
}


int matrixchainorder(int *P,int length){
  int n,i,j,k;
  int q;
  int l;

  n = length;

  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] = INF;
      for(k=i;k<=j-1;k++){
	q = m[i][k] + m[k+1][j] + P[i-1]*P[k]*P[j];
	if(m[i][j] > q){
	  m[i][j] = q;
	  //printf("q = %d\n",q);
	}
      }
    }
  }

  /*printf("DEBUG\n");
  for(int a = 7; a >= 1; a--){
    for(int b = 0; b <= 6; b++){
      printf("%d ", m[b][a]);

    }
    printf("\n");
  }
  */

  return m[1][n];
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll dp[110][110];

int main() {
    ll N;
    cin >> N;
    vll p;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        if(i == 0) p.emplace_back(a);
        p.emplace_back(b);
    }

    rep(i, 110) rep(j, 110) dp[i][j] = INF;
    rep(i, 100) dp[i][i] = 0;

    for(ll l = 2; l <= N; l++) rep(i, N-l+1) {
        ll j = i + l - 1;
        for(ll k = i; k < j; k++) chmin(dp[i][j], dp[i][k] + dp[k+1][j] + p[i] * p[k+1] * p[j+1]);
    }
    cout << dp[0][N-1] << endl;
}

C++: #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll n;
vector<ll> r(100), c(100);
vector<vector<ll> > dp(101, vector<ll>(101, -1));
int dfs(int v, int w) {
    // cout << v << ":" << w << endl;
    if(dp[v][w] != -1) {
        return dp[v][w];
    } else {
        ll tmp = INT_MAX / 3;
        for(int i = v + 1; i < w; i++) {
            tmp = min(tmp, dfs(v, i) + dfs(i, w) + r[v] * r[i] * c[w - 1]);
        }
        dp[v][w] = tmp;
        return tmp;
    }
}
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> r[i] >> c[i];
    }
    for(int i = 0; i < n; i++) {
        dp[i][i] = 0;
        dp[i][i + 1] = 0;
    }
    dfs(0, n);
    cout << dp[0][n] << endl;
}

C++: #include <iostream>

using namespace std;

const int N = 100;

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

int main()
{
    int n;
    int rc[N+1];
    int mat[N + 1][N] = {};
    cin >> n;

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

    // 行列の長さl
    for (int l = 2; l < n + 1; l++)
    {
        // i番目の積 積の数は : n - l + 1
        for (int i = 1; i < n - l + 2; i++)
        {
            mat[l][i] = (1 << 21);
            for (int k = 1; k < l; k++)
            {
                mat[l][i] = min(mat[l][i], mat[k][i] + mat[l - k][i + k] + rc[i-1] * rc[i+k-1] * rc[i+l-1]);
            }
        }
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll dp[100][100];
vector<pair<int,int>> matrix(100);


ll kukandp(int i, int j){
    if(dp[i][j]!=INF)return dp[i][j];
    if(j-i==0)dp[i][j]=0;
    if(j-i==1)dp[i][j]=matrix[i].first*matrix[i].second*matrix[j].second;

    if(j-i>1){
        for(int k=i; k<j; k++){
            dp[i][j]=min(dp[i][j], kukandp(i,k)+kukandp(k+1,j)+matrix[i].first*matrix[k].second*matrix[j].second);
        }
    }

    return dp[i][j];
}

int main(){
    int N; cin>>N;
    rep(i,N){
        cin>>matrix[i].first>>matrix[i].second;
    }
    rep(i,100)rep(j,100)dp[i][j]=INF;
    cout<<kukandp(0,N-1)<<endl;
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define LL long long
using namespace std;
int main()
{
    int a[200],n,m[200][200],i;
    cin>>n;
    for (i=1; i<=n; i++)
    {
        cin>>a[i-1]>>a[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]+a[i-1]*a[k]*a[j]);
            }
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}