#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[2 * n + 2], i, sum = 0, diff, prev = 1;
  for (i = 1; i <= 2 * n; i = i + 1) {
    cin >> a[i];
  }
  unordered_map<long long int, long long int> mps, mpe;
  for (i = 1; i <= 2 * n; i = i + 1) {
    if (mps[a[i]] == 0) {
      mps[a[i]] = i;
    }
  }
  for (i = 2 * n; i >= 1; i = i - 1) {
    if (mpe[a[i]] == 0) {
      mpe[a[i]] = i;
    }
  }
  for (i = 1; i <= n; i = i + 1) {
    diff = mps[i] - prev;
    if (diff < 0) {
      diff = -1 * diff;
    }
    sum = sum + diff;
    prev = mps[i];
  }
  prev = 1;
  for (i = 1; i <= n; i = i + 1) {
    diff = mpe[i] - prev;
    if (diff < 0) {
      diff = -1 * diff;
    }
    sum = sum + diff;
    prev = mpe[i];
  }
  cout << sum << endl;
}
