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 <iostream>
#include <algorithm>
#include <cstdlib>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;


typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> data;
const ll INF = 1LL <<50;

data dp[200][200][2];

ll mul(data d1, data d2){
  return d1.second.first * d1.second.second * d2.second.first * d2.second.second;
}

P get_minP(data d1, data d2){
  ll a = d1.second.first * d2.second.second;
  ll b = d2.second.first * d1.second.second;
  if(a < b) return P(d1.second.first, d2.second.second);
  else return P(d2.second.first, d1.second.second);
}

int main(){
  int n;
  cin >> n;
  fill(&dp[0][0][0], &dp[199][199][1] + 1, data(INF, P(0, 0)));
  rep(i, n){
    cin >> dp[i][1][0].second.first >> dp[i][1][0].second.second;
    dp[i][1][1].second.first = dp[i][1][0].second.first;
    dp[i][1][1].second.second = dp[i][1][0].second.second;
    dp[i][1][0].first = dp[i][1][1].first= 0;
  }
  for(int i = 2; i <= n; i++){
    for(int j = 0; j <= n - i; j++){
      for(int k = 1; k < i; k++){
	ll cost = dp[j][k][0].first + dp[j+k][i-k][0].first 
	  + mul(dp[j][k][0], dp[j+k][i-k][0]);
	
	P m1 = get_minP(dp[j][k][0], dp[j+k][i-k][1]);
	P m2 = get_minP(dp[j][k][1], dp[j+k][i-k][0]);
	
	if(cost < dp[j][i][0].first || 
	   cost == dp[j][i][0].first && m1.first * m1.second < 
	   dp[j][i][0].second.first * dp[j][i][0].second.second){
	  
	  dp[j][i][0] = dp[j][i][1] = data(cost, m1);
	  
	}else if(cost == dp[j][i][0].first && m1.first * m1.second == 
		 dp[j][i][0].second.first * dp[j][i][0].second.second){
	    
	  if(m1.first < dp[j][i][0].second.first){
	    dp[j][i][0].second = m1;
	  }
	  if(m1.second < dp[j][i][1].second.second){
	    dp[j][i][1].second = m1;
	  }
	    
	  if(cost < dp[j][i][0].first || 
	     cost == dp[j][i][0].first && m2.first * m2.second < 
	     dp[j][i][0].second.first * dp[j][i][0].second.second){
	    
	    dp[j][i][0] = dp[j][i][1] = data(cost, m2);

	  }else if(cost == dp[j][i][0].first && m2.first * m2.second == 
		   dp[j][i][0].second.first * dp[j][i][0].second.second){
	    if(m2.first < dp[j][i][0].second.first){
	      dp[j][i][0].second = m2;
	    }
	    if(m2.second < dp[j][i][1].second.second){
	      dp[j][i][1].second = m2;
	    }
	  } 
	  
	}
      }
      //	cout << dp[j][i][0].first << " " << "i " << i << " j " << j << endl;
    }
  }
  cout << dp[0][n][0].first << endl;
  return 0;
}

C++: #include<iostream>

using namespace std;

int memo[100][100];

int main()
{
	int n;	cin>>n;
	int card[100][2];
	for(int i=0;i<n;i++){
		cin>>card[i][0]>>card[i][1];
		for(int j=0;j<n-i;j++)	memo[i][j]=(1U<<31)-1;
	}

	for(int j=0;j<n;j++)	memo[0][j]=0;
	for(int i=1;i<n;i++){
		for(int j=0;j<n-i;j++){
			for(int k=0;k<i;k++){
				int cost=card[j][0]*card[j+k][1]*card[j+k+1][0]*card[j+i][1];
				memo[i][j]=min(memo[i][j],memo[k][j]+memo[i-k-1][j+k+1]+cost);
			}
		}
	}

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

	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
long memo[100][100];
long a[100],b[100];
long f(int l,int r)
{
	if(memo[l][r]>0)return memo[l][r];
	else if(l+1==r)return a[l]*b[l]*a[r]*b[r];
	long ans=1LL<<32;
	for(int i=l+1;i<r;i++)
	{
		long now;
		if(i==l+1)
		{
			now=f(i,r)+a[l]*b[l]*a[i]*b[r];
		}
		else if(i==r-1)
		{
			now=f(l,i)+a[l]*b[i]*a[r]*b[r];
		}
		else
		{
			now=f(l,i)+f(i+1,r)+a[l]*b[i]*a[i+1]*b[r];
		}
		ans=min(ans,now);
	}
	return memo[l][r]=ans;
}
main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	cout<<(n==1?0:f(0,n-1))<<endl;
}

C++: #include <cstdio>
#include <cstring>

int n;
int a[101],b[101];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	int res=0;
	for(int i=0;i<n-1;i++){
		int f=-1,t=-1;
		for(int j=0;j<n;j++){
			if(a[j]==-1)continue;
			for(int k=0;k<n;k++){
				if(b[k]==-1 || j==k)continue;
				if(f==-1 || t==-1){
					f=j;
					t=k;
				}else if(a[f]*b[t]<a[j]*b[k]){
					f=j;
					t=k;
				}
			}
		}
		res+=a[f]*a[t]*b[f]*b[t];
		a[f]=a[t];
		a[t]=-1;
		b[t]=-1;
	}
	printf("%d\n",res);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 1LL << 60;
LL a[100], b[100];
LL dp[100][100];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld %lld", &a[i], &b[i]);
	}
	
	for (int i = 0; i < 100; i++){
		for (int j = 0; j < 100; j++){
			dp[i][j] = INF;
		}
		dp[i][i] = 0;
	}
	
	for (int w = 1; w < n; w++){
		for (int l = 0; l + w < n; l++){
			for (int i = l; i <= l + w; i++){
				LL C = a[l] * b[i] * a[i + 1] * b[l + w];
				LL sum = dp[l][i] + dp[i + 1][l + w] + C;
				dp[l][l + w] = min(dp[l][l + w], sum);
			}
		}
	}
	
	printf("%lld\n", dp[0][n - 1]);
	
	return 0;
}