#include <bits/stdc++.h>
using namespace std;
int N;
pair<int, int> a[200002 + 1];
int min(int a, int b) { return a > b ? b : a; }
int abs(int a) { return a < 0 ? -a : a; }
int main() {
  cin >> N;
  N *= 2;
  int b;
  for (int i = 0; i < N; i++) {
    cin >> b;
    a[i] = {b, i};
  }
  sort(a, a + N);
  long long ans = a[0].second + a[1].second;
  for (int i = 2; i < N; i += 2) {
    ans += min(abs(a[i - 2].second - a[i].second) +
                   abs(a[i - 1].second - a[i + 1].second),
               abs(a[i - 1].second - a[i].second) +
                   abs(a[i - 2].second - a[i + 1].second));
  }
  cout << ans << '\n';
  return 0;
}
