#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(100001, -1);
  vector<int> b(100001, -1);
  for (int i = 1; i <= 2 * n; i++) {
    int x;
    cin >> x;
    if (a[x] == -1)
      a[x] = i;
    else
      b[x] = i;
  }
  int want = 1;
  auto walked = 0LL;
  array<int, 2> at = {1, 1};
  want = 1;
  while (want != n + 1) {
    if (abs(a[want] - at[0]) + abs(b[want] - at[1]) >
        abs(a[want] - at[1]) + abs(b[want] - at[0]))
      swap(a[want], b[want]);
    walked += abs(a[want] - at[0]) + abs(b[want] - at[1]);
    at[0] = a[want];
    at[1] = b[want];
    want++;
  }
  cout << walked << endl;
  return 0;
}
