#include <bits/stdc++.h>
#include <vector>

using namespace std;
unsigned long long fun(int n, int suma, int target, unordered_set<int> comp){
    if(suma == target){
        if(comp.size() == n)
            return 0;
        else{
            if(n % 2 == 0)
                return ((n / 2) - 1) * (n / 2);
            else
                return ((n - 1) / 2) * (((n - 1) / 2) + 1);
        }
    }else{
        return abs(target - suma);
    }
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    int n;
    scanf("%d", &n);
    int target = (n * (n + 1)) / 2;
    unordered_set<int> comp1;
    unordered_set<int> comp2;
    int k1, k2;
    int sum1 = 0, sum2 = 0;
    for(int i = 0;i < n;i++){
        scanf("%d %d", &k1, &k2);
        sum1 += k1; sum2 += k2;
        auto it = comp1.find(k1);
        if(it == comp1.end()){
            comp1.insert(k1);
        }
        it = comp2.find(k2);
        if(it == comp2.end()){
            comp2.insert(k2);
        }
    }
    unsigned long long ans = 0;
    ans = ans + fun(n, sum1, target, comp1);
    ans = ans + fun(n, sum2, target, comp2);
    printf("%llu", ans);
}