#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
int m[100010][3];
void solve () {
int n, ans = 0;
cin >> n;
for (int i = 1; i <= 2*n; i++) {
int x, y;
cin >> x >> y;
if (x < 1) ans += 1 - x, x = 1;
else if (x > n) ans += x - n, x = n;
if (y < 1) ans += 1 - y, y = 1;
else if (y > 2) ans += y - 2, y = 2;
m[x][y]++;
}
int a = 0, b = 0;
for (int i = 1; i <= n; i++) {
a += m[i][1] - 1, b += m[i][2] - 1;
while (a > 0 && b < 0) {a--; b++; ans++;}
while (a < 0 && b > 0) {a++, b--, ans++;}
ans += abs(a) + abs(b);
}
cout << ans;
}
signed main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |