#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll,ll> p;
const int N = 1e3+34;

int a[N],b[N];
int dp[N][N],cnt[3*N]; /// 0 = levo,1 = desno
p nesto[N];
int n;

bool cmp(p x,p y){
    return x.second < y.second;
}

bool levo[N];

ll res = 1e15;

void brut(ll i){
    if(i == n+1){
        ll rez = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                if(!levo[i]){
                    if((!levo[j] && a[j] < a[i] && b[j] > b[i]) || (levo[j] && a[j] < b[i] && b[j] > b[i])){
                        rez++;
                    }
                }
                else{
                    if(levo[j] && a[j] < b[i] && b[j] > b[i]){
                        rez++;
                    }
                }
            }
        }
        res = min(res,rez);
        return;
    }
    levo[i] = 1;
    brut(i+1);
    levo[i] = 0;
    brut(i+1);
}

ll Resi(int N,int *A,int *B){
    n = N;
    for(int i = 1; i <= n; i++){
        a[i] = A[i-1];
        b[i] = B[i-1];
        cnt[b[i]]++;
        nesto[i] = p(a[i],b[i]);
    }
    for(int i = 1; i <= 2*n; i++){
        cnt[i] += cnt[i-1];
    }
    sort(nesto+1,nesto+n+1,cmp);
    for(int i = 1; i <= n; i++){
        a[i] = nesto[i].first;
        b[i] = nesto[i].second;
    }
    brut(1);
    return res;
}
/*int main(){
    int n1[4],n2[4];
    n1[0] = 0;
    n1[1] = 1;
    n1[2] = 2;
    n1[3] = 5;
    n2[0] = 3;
    n2[1] = 7;
    n2[2] = 4;
    n2[3] = 6;
    cout << Resi(4,n1,n2) << endl;
}*/