#include <bits/stdc++.h>
using namespace std;
int n;
pair<long long, long long> p[200200];
int main() {
  cin >> n;
  n *= 2;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    p[i] = pair<long long, long long>(x, i);
  }
  sort(p, p + n);
  long long ans = 0;
  ans += p[0].second;
  ans += p[1].second;
  for (int i = 2; i < n; i += 2) {
    ans += abs(p[i].second - p[i - 2].second);
    ans += abs(p[i + 1].second - p[i - 1].second);
  }
  cout << ans << endl;
}
