#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  long long f1[n + 4], f2[n + 4];
  fill(f1, f1 + n + 4, -1LL);
  fill(f2, f2 + n + 4, -1LL);
  long long a[(n << 1)];
  for (int i = 0; i < (n << 1); ++i) {
    cin >> a[i];
    if (f1[a[i]] != -1)
      f2[a[i]] = i + 1;
    else
      f1[a[i]] = i + 1;
  }
  long long ans = 0, p1 = 1, p2 = 1;
  for (int i = 1; i <= n; ++i) {
    assert(f1[i] != -1 && f2[i] != -1);
    if (abs(p1 - f1[i]) + abs(p2 - f2[i]) > abs(p2 - f1[i]) + abs(p1 - f2[i])) {
      ans += (abs(p2 - f1[i]) + abs(p1 - f2[i]));
      p1 = f2[i];
      p2 = f1[i];
    } else {
      ans += (abs(p1 - f1[i]) + abs(p2 - f2[i]));
      p1 = f1[i];
      p2 = f2[i];
    }
  }
  cout << ans << endl;
  return 0;
}
