#pragma GCC optimize("Ofast,unroll-loops") #include using namespace std; map>m; int dist(int x, int y, int u, int v){ return abs(x-u)+abs(y-v); } int main(){ long long sum=0; int cnt, x,y; cin >> cnt; while(cnt--){ cin >> x >> y; if(m.find(x)!=m.end()) m[x] = {min(m[x].first, y), max(m[x].second, y)}; else m[x] = {y,y}; } set s; int ss=0,nylast,ylast=-1,mi,tfirst = -2; for(auto it1=m.begin(), it2=next(m.begin());it2!=m.end();++it1,++it2){ mi = dist(it1->first,it1->second.first, it2->first,it2->second.first); tfirst = it1->second.first; nylast = it2->second.first; if(mi > dist(it1->first,it1->second.second, it2->first,it2->second.first)){ tfirst = it1->second.second; nylast = it2->second.first; mi = dist(it1->first,it1->second.second, it2->first,it2->second.first); } if(mi > dist(it1->first,it1->second.first, it2->first,it2->second.second)){ tfirst = it1->second.first; nylast = it2->second.second; mi = dist(it1->first,it1->second.first, it2->first,it2->second.second); } if(mi > dist(it1->first,it1->second.second, it2->first,it2->second.second)){ tfirst = it1->second.second; nylast = it2->second.second; mi = dist(it1->first,it1->second.second, it2->first,it2->second.second); } if(ylast == tfirst) s.insert(ss); sum+=mi; ylast = nylast; ++ss; } ss=0; for(auto&x:m){ sum+=(s.count(ss))*abs(x.second.first-x.second.second)+abs(x.second.first-x.second.second); ++ss; } cout << sum << "\n"; }