#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[100005], b[100005];
  long long ans = 0;
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= 2 * n; i++) {
    int temp;
    cin >> temp;
    if (a[temp] != 0)
      b[temp] = i;
    else
      a[temp] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      ans += a[i] - 1 + b[i] - 1;
    } else {
      long long a1, a2;
      a1 = ans + abs(a[i - 1] - a[i]) + abs(b[i - 1] - b[i]);
      a2 = ans + abs(a[i - 1] - b[i]) + abs(b[i - 1] - a[i]);
      ans = a1 < a2 ? a1 : a2;
    }
  }
  cout << ans << endl;
  return 0;
}
