Go: package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	P := make([]int, n+1)
	for i := 1; i <= n; i++ {
		l := nextInt(sc)
		P[i-1] = l
		m := nextInt(sc)
		P[i] = m
	}

	matrix := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		matrix[i] = make([]int, n+1)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n - l + 1; i++ {
			j := i + l - 1
			matrix[i][j] = (1 << 21)
			for k := i; k <= j-1; k++ {
				matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k+1][j] + P[i-1] * P[k] * P[j])
			}
		}
	}
	fmt.Println(matrix[1][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];
	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[i][n] << endl;
	
	return 0;
}

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

struct mat{
  int row, col;
};

int m[101][101];
mat p[101];

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> p[i].row >> p[i].col;
  for(int l = 2; l <= n; l++){
    for(int i = 1; i <= n - l + 1; i++){
      int j = i + l - 1;
      if(i == j) m[i][j] = 0;
      else{
	int minc = 1e9;
	for(int k = i; k < j; k++){
	  int x = m[i][k] + m[k+1][j] + p[i].row * p[k].col * p[j].col;
	  minc = minc < x ? minc : x;
	}
	m[i][j] = minc;
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}