Data Constraint
n100000

# SRC

#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespace std ;#define N 100000 + 10typedef long long ll ;struct Note {    int v , h ;} tpx[N] , tpy[N] ;struct Point {    int x , y ;    Point ( int X = 0 , int Y = 0 ) { x = X , y = Y ; }} P[N] ;struct Tree {    ll sum ;    int tot ;    Tree ( ll S = 0 , int T = 0 ) { sum = S , tot = T ; }} Tr[2][N] ;Tree operator + ( Tree a , Tree b ) { return Tree( a.sum + b.sum , a.tot + b.tot ) ; }int Orix[N] , Oriy[N] ;int n , Cntx , Cnty ;ll ans = 1e15 ;bool cmp( Note a , Note b ) { return a.v < b.v ; }void PreX() {    sort( tpx + 1 , tpx + n + 1 , cmp ) ;    tpx[0].v = 0x7FFFFFFF ;    for (int i = 1 ; i <= n ; i ++ ) {        if ( tpx[i].v != tpx[i-1].v ) ++ Cntx ;        Orix[Cntx] = P[tpx[i].h].x ;        P[tpx[i].h].x = Cntx ;    }}void PreY() {    sort( tpy + 1 , tpy + n + 1 , cmp ) ;    tpy[0].v = 0x7FFFFFFF ;    for (int i = 1 ; i <= n ; i ++ ) {        if ( tpy[i].v != tpy[i-1].v ) ++ Cnty ;        Oriy[Cnty] = P[tpy[i].h].y ;        P[tpy[i].h].y = Cnty ;    }}int lowbit( int x ) { return x & (-x) ; } ;void Insert( int k , int x , Tree del ) {    while ( x <= n ) {        Tr[k][x] = Tr[k][x] + del ;        x += lowbit(x) ;    }}Tree Find( int k , int x ) {    Tree ret = Tree(0,0) ;    while ( x >= 1 ) {        ret = ret + Tr[k][x] ;        x -= lowbit(x) ;    }    return ret ;}int main() {    scanf( "%d" , &n ) ;    for (int i = 1 ; i <= n ; i ++ ) {        scanf( "%d%d" , &P[i].x , &P[i].y ) ;        P[i] = Point( P[i].x - P[i].y , P[i].x + P[i].y ) ;        tpx[i].v = P[i].x ;        tpy[i].v = P[i].y ;        tpx[i].h = tpy[i].h = i ;    }    PreX() ;    PreY() ;    for (int i = 1 ; i <= n ; i ++ ) {        Insert( 0 , P[i].x , Tree( Orix[P[i].x] , 1 ) ) ;        Insert( 1 , P[i].y , Tree( Oriy[P[i].y] , 1 ) ) ;    }    for (int i = 1 ; i <= n ; i ++ ) {        ll now = 0 ;        Tree All = Find( 0 , Cntx ) ;        Tree Lef = Find( 0 , P[i].x - 1 ) ;        Tree Rig = Tree( All.sum - Lef.sum , All.tot - Lef.tot ) ;        now = (ll)Lef.tot * Orix[P[i].x] - Lef.sum ;        now += Rig.sum - (ll)Rig.tot * Orix[P[i].x] ;        All = Find( 1 , Cnty ) ;        Lef = Find( 1 , P[i].y - 1 ) ;        Rig = Tree( All.sum - Lef.sum , All.tot - Lef.tot ) ;        now += (ll)Lef.tot * Oriy[P[i].y] - Lef.sum ;        now += (ll)Rig.sum - (ll)Rig.tot * Oriy[P[i].y] ;        ans = min( ans , now ) ;    }    printf( "%lld\n" , ans / 2 ) ;    return 0 ;}

1 0