#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  pair<long long, long long> p[n * 2];
  long long po;
  for (int i = 0; i < n * 2; i++) {
    cin >> po;
    p[i].first = po;
    p[i].second = i + 1;
  }
  sort(p, p + 2 * n);
  long long s = p[0].second - 1, d = p[1].second - 1;
  for (int i = 2; i < n * 2; i++) {
    if (i % 2 == 0) {
      s += abs(p[i].second - p[i - 2].second);
    } else {
      d += abs(p[i].second - p[i - 2].second);
    }
  }
  cout << s + d << "\n";
  return 0;
}
