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<set>
#include<cstring>
#include<algorithm>

using namespace std;

int CardDataA[100], CardDataB[100];
int DpResult[100][100];
const int INF = 50000000;

void Init() {
	memset(CardDataA, 0, sizeof(CardDataA));
	memset(CardDataB, 0, sizeof(CardDataB));

	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			DpResult[i][j] = INF;
		}
	}

	for (int i = 0; i < 100; i++) {
		DpResult[i][i] = 0;
	}
}

void solve(int n) {
	int current;

	for (int k = 1; k < n; k++) {
		for (int i = 0; i+k < n; i++) {
			for (int j = i; j < i + k; j++) {
				current = CardDataA[i] * CardDataB[j] * CardDataA[j + 1] * CardDataB[i + k];
				DpResult[i][i+k] = min(DpResult[i][i+k], DpResult[i][j] + DpResult[j+1][i+k] + current);
				//cout << "current:"<<current << "  Dp["<<i<<"]"<< "[" << i+k << "]=" << DpResult[i][i+k]<< endl;
			}
		}
	}
		
}

int main() {
	int n;

	Init();

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> CardDataA[i] >> CardDataB[i];
	}
	/*n = 0;
	while (CardDataA[n] != 0) {
		cout << CardDataA[n] << "  " << CardDataB[n] << endl;
		n++;
	}*/
	solve(n);
	cout << DpResult[0][n-1] << endl;

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef pair<int,int> pii;
int const INF = 1<<30;
int main() {
  int n;
  cin >> n;
  vector<int> v1(n),v2(n);
  REP(i,n) {
    cin >> v1[i] >> v2[i];
  }
  int ans = 0;
  while(v1.size()>1) {
    pii t1(INF,0),t2(INF,0),b1(INF,0),b2(INF,0);
    REP(i,v1.size()) {
      if (t1>pii(v1[i],i)) {
        t2 = t1;
        t1 = pii(v1[i],i);
      } else {
        t2 = min(pii(v1[i],i),t2);
      }
      if (b1>pii(v2[i],i)) {
        b2 = b1;
        b1 = pii(v2[i],i);
      } else {
        b2 = min(pii(v2[i],i),b2);
      }
    }
    int ue,shita;
    if (t1.second == b1.second) {
      if (t2.first < b2.first) {
        ue = t2.second;
        shita = b1.second;
      } else {
        ue = t1.second;
        shita = b2.second;
      }
    } else {
      ue = t1.second;
      shita = b1.second;
    }
     // cout << ue << " " << shita<< endl;
     // cout << v1[ue] << endl;
    ans += v1[ue]*v2[ue]*v1[shita]*v2[shita];
    v1.push_back(v1[ue]);
    v2.push_back(v2[shita]);
     // REP(i,v1.size()) {
     //   cout << i << ": "<< v1[i] << " " <<v2[i] << endl;
     // }
    if (ue<shita) shita--;
    v1.erase(v1.begin()+ue);
    v1.erase(v1.begin()+shita);
    v2.erase(v2.begin()+ue);
    v2.erase(v2.begin()+shita);
  }
  cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int a[100];
int b[100];

int solve(int pos, int num){
  int ret = INT_MAX;
  if(num == 1) return 0;
  REP(i,num-1){
    int t = pos + i;
    int cost = solve(pos,i+1) + solve(pos+i+1,num-i-1);
    cost += a[pos] * b[t] * a[t+1] * b[pos+num-1];
    ret = min(ret, cost);
  }
  return ret;
}

int main(){
  int n;
  scanf("%d",&n);
  REP(i,n) scanf("%d%d",&a[i],&b[i]);
  printf("%d",solve(0,n));
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
#include <cassert>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

vector<pii> v;

ll dp[110][110];

ll f(int l, int r){
	if(dp[l][r] != -1) return dp[l][r];
	assert(l >= 0 && r < v.size());
	ll ret = 1e18;
	for(int i = l; i < r; i++) {
		ret = min(ret, f(l, i) + f(i+1, r) + v[l].fi*v[i].se*v[i+1].fi*v[r].se);
	}
	return dp[l][r] = ret;
}

int main(){
	int n;
	cin>>n;
	v.resize(n);
	rep(i, n) cin>>v[i].fi>>v[i].se;
	rep(i, 110) rep(j, 110) dp[i][j] = -1;
	rep(i, 110) dp[i][i] = 0;
	cout<<f(0, n-1)<<endl;
}