Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7fffffff
func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	top := make([]int, 0)
	bottom := make([]int, 0)
	for i := 0; i < n; i++ {
		scanner.Scan()
		buf := strings.Split(scanner.Text(), " ")
		a, _ := strconv.Atoi(buf[0])
		b, _ := strconv.Atoi(buf[1])
		top = append(top, a)
		bottom = append(bottom, b)
	}
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = INF
		}
	}
	for j := 0; j < n; j++ {
		dp[0][j] = 0
	}
	for i := 1; i < n; i++ {
		for j := 0; j < n-i; j++ {
			tmp := make([]int, 0)
			for k := 0; k < i; k++ {
				tmp = append(tmp, dp[k][j] + dp[i - k - 1][j + k + 1] +top[j] * bottom[j + k] * top[j + k + 1] * bottom[j + i])
			}
			sort.Ints(tmp)
			dp[i][j] = tmp[0]
		}
	}
	fmt.Println(dp[n-1][0])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

C++: #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

const int INF = 1 << 29;

int main() {
    int n;
    vector<P> a;

    cin >> n;
    a.resize(n);
    for (int j = 0; j < n; ++j) {
        cin >> a[j].first >> a[j].second;
    }

    int m[105][105];
    for (int j = 0; j < n; ++j) {
        fill(m[j], m[j] + 105, INF);
        m[j][j] = m[j][j+1] = 0;
    }

    for (int j = 2; j <= n; ++j) {
        for (int k = 0; k + j <= n; ++k) {
            for (int l = 1; l < j; ++l) {
                m[k][k+j] = min(m[k][k+j],
                        m[k][k+l] + m[k+l][k+j] + a[k].first * a[k+l-1].second * a[k+l].first * a[k+j-1].second);
            }
        }
    }

    cout << m[0][n] << endl;

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	pair<int, int> c[100];
	for (int i = 0; i < n; ++i)
		scanf("%d %d", &c[i].first, &c[i].second);

	int d[100][100];
	for (int i = 0; i < 100; ++i)
		for (int j = 0; j < 100; ++j)
			d[i][j] = INT_MAX;
	for (int i = 0; i < 100; ++i)
		d[i][i] = 0;

	for (int k = 1; k < n; ++k)
		for (int i = 0; i < n-k; ++i)
			for (int j = i; j < i+k; ++j)
				d[i][i+k] = min(d[i][i+k]
			, d[i][j]+d[j+1][i+k] + c[i].first*c[j].second*c[j+1].first*c[i+k].second);

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;

// INF
#define IINF (INT_MAX/2)
#define INF (1<<29)

// math
#define SQ(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)

// rep
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

// dx, dy
int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};

// inRange
inline bool inRange(int x, int y, int W, int H) {
  return 0<=x && x<W && 0<=y && y<H;
}

// isPalindrome
inline bool isPalindrome(string s) {
  return equal(s.begin(), s.end(), s.rbegin());
}

ll cfront[100], cback[100];

ll memo[101][101];

ll dfs(int l, int r) {
  
  if(memo[l][r]) return memo[l][r];
  if(l+1 == r) return 0;
  
  ll ret = INF;
  REP(m, l+1, r) {
    ret = min(ret, dfs(l, m) + dfs(m, r)
              + cfront[l]*cback[m-1]*cfront[m]*cback[r-1]);
  }
  
  return memo[l][r] = ret;
}

int main() {
  int N; cin >> N;
  rep(i, N)
    cin >> cfront[i] >> cback[i];
  cout << dfs(0, N) << endl;
  
  return 0;
}

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

int u[100], b[100];
int dp[100][100];

int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> u[i] >> b[i];
  }

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

  for(int i = 1; i <= n; i++){
    for(int j = 0; j < n - i; j++){
      for(int k = j; k < j + i; k++){
        dp[j][j+i] = min(dp[j][j+i], dp[j][k] + dp[k+1][j+i] + u[j] * b[k] * u[k+1] * b[j+i]);
      }
    }
  }

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

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[110],b[110];
Int dp[110][110];

Int f(int n,int m){
	if(dp[n][m]!=0)return dp[n][m];
	if(n==m)return 0;
	int i;
	Int mn=1000000000000LL;
	for(i=n;i<m;i++){
		chmin(mn,f(n,i)+f(i+1,m)+a[n]*b[i]*a[i+1]*b[m]);
	}
	dp[n][m]=mn;
	return mn;
}

int main() {
	int n,i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	cout<<f(0,n-1)<<endl;
	return 0;
}

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

#define fi first
#define se second

#define INF (1LL << 31)

typedef pair<long long, long long> pll;

int main() {
	int n;
	vector<pll> in;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		in.push_back(pll(a,b));
	}

	long long dptab[128][128];
	for(int i = 0; i < 128; i++) for(int j = 0; j < 128; j++) dptab[i][j] = INF;

	for(int i = 0; i < n; i++) {
		dptab[0][i] = dptab[1][i] = 0;
		dptab[2][i] = in[i].fi * in[i].se * in[i + 1].fi * in[i + 1].se;
	}
	for(int width = 0; width <= n; width++) {
		for(int start = 0; start < n; start++) {
			for(int div = 1; div < width; div++) {
				dptab[width][start] = min(dptab[width][start],
						dptab[div][start] + dptab[width - div][start + div] + in[start].fi * in[start + div - 1].se * in[start + div].fi * in[start + width - 1].se);
			}
		}
	}

	cout << dptab[n][0] << endl;

	return 0;
}