#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair<long long,long long> arr[2*n];
long long ans=0;
int got[n+1];
memset(got,0,sizeof(got));
int up=0;
for(int i=0; i<2*n; i++){
cin >> arr[i].first >> arr[i].second;
if(arr[i].first<1){
ans+=1-arr[i].first;
arr[i].first=1;
}
if(arr[i].first>n){
ans+=arr[i].first-n;
arr[i].first=n;
}
if(arr[i].second<1){
ans+=1-arr[i].second;
arr[i].second=1;
}
if(arr[i].second>2){
ans+=arr[i].second-2;
arr[i].second=2;
}
got[arr[i].first]++;
if(arr[i].second==2) up++;
}
ans+=abs(up-n);
int cur=0;
for(int i=1; i<=n; i++){
cur+=got[i];
ans+=abs(cur-i*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... |