#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
struct node{
int x;
int pos;
};
node a[1000005];
bool cmp(node a,node b){
if(a.x != b.x) return a.x < b.x;
return a.pos < b.pos;
}
int main()
{
int n;
cin >> n;
if(n == 0){
cout << 0 << endl;
return 0;
}
for(int i = 1;i <= 2*n;i++){
int t;
cin >> t;
a[i].pos = i;
a[i].x = t;
}
sort(a+1,a+2*n+1,cmp);
// for(int i = 1;i <= n;i++){
// cout << a[i].x << " " << a[i].pos << endl;
// }
// cout << endl;
// for(int i = 1;i <= n;i++){
// cout << b[i].x << " " << b[i].pos << endl;
// }
long long sum = a[1].pos - 1 + a[2].pos - 1;//不开longlong见祖宗
for(int i = 2;i <= n;i++){
int x1 = a[2*i - 3].pos;
int x2 = a[2*i - 2].pos;
int y1 = a[2*i - 1].pos;
int y2 = a[2*i].pos;
if(abs(x1 - y1) + abs(x2 - y2) < abs(x2 - y1) + abs(x1 - y2)){
sum +=(long long) abs(x1 - y1) + abs(x2 - y2);
}
else{
sum +=(long long)abs(x2 - y1) + abs(x1 - y2);
}
}
cout << sum << endl;
return 0;
}