#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
int n; cin >> n;
pair<int,int> c[2*n];
for (int i = 0; i < 2*n; i++) {
cin >> c[i].first >> c[i].second;
}
sort(c, c + 2*n);
int ans = 0;
for (int i = 0; i < n; i++) {
if (c[2*i].second >= 2) ans=ans+abs(c[2*i].first-(i+1))+abs(c[2*i].second-2)+abs(c[2*i+1].first-(i+1))+abs(c[2*i+1].second-1);
else ans=ans+abs(c[2*i].first-(i+1))+abs(c[2*i].second-1)+abs(c[2*i+1].first-(i+1))+abs(c[2*i+1].second-2);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |