#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[2 * n];
  long long f1[n];
  long long f2[n];
  for (long long i = 0; i < n; i++) f1[i] = -1;
  for (long long i = 0; i < 2 * n; i++) {
    cin >> a[i];
    a[i]--;
    if (f1[a[i]] == -1)
      f1[a[i]] = i;
    else
      f2[a[i]] = i;
  }
  long long sol = f1[0] + f2[0];
  for (long long i = 1; i < n; i++) {
    sol += abs(f1[i] - f1[i - 1]);
    sol += abs(f2[i] - f2[i - 1]);
  }
  cout << sol << endl;
}
