#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[100005], b[100005];
int32_t main() {
int n; cin >> n;
for(int i = 1; i <= n; ++ i) cin >> a[i] >> b[i];
// sắp xếp mảng a, b
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
int ans = 0;
for(int i = 1; i <= n; ++ i) {
// làm theo công thức
ans += abs(a[i] - b[i]);
}
cout << ans;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IGFbMTAwMDA1XSwgYlsxMDAwMDVdOwoKaW50MzJfdCBtYWluKCkgewogICAgaW50IG47IGNpbiA+PiBuOwogICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyArKyBpKSBjaW4gPj4gYVtpXSA+PiBiW2ldOwoKICAgIC8vIHPhuq9wIHjhur9wIG3huqNuZyBhLCBiCiAgICBzb3J0KGEgKyAxLCBhICsgMSArIG4pOwogICAgc29ydChiICsgMSwgYiArIDEgKyBuKTsKICAgIGludCBhbnMgPSAwOwogICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyArKyBpKSB7CiAgICAgICAgLy8gbMOgbSB0aGVvIGPDtG5nIHRo4bupYwogICAgICAgIGFucyArPSBhYnMoYVtpXSAtIGJbaV0pOwogICAgfQogICAgY291dCA8PCBhbnM7Cn0=