#include <bits/stdc++.h>
using namespace std;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long long NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
const int N = 2e5 + 10;
int n, a[N];
pair<int, int> pos[N];
int main() {
  scanf("%d", &n);
  memset(pos, -1, sizeof pos);
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &a[i]);
    if (pos[a[i]].first != -1)
      pos[a[i]].second = i;
    else
      pos[a[i]].first = i;
  }
  long long cost = 0LL;
  pos[0].first = pos[0].second = 1;
  for (int i = 0; i <= n - 1; i++) {
    int x = INF;
    x = min(x, abs(pos[i].first - pos[i + 1].first) +
                   abs(pos[i].second - pos[i + 1].second));
    x = min(x, abs(pos[i].first - pos[i + 1].second) +
                   abs(pos[i].second - pos[i + 1].first));
    cost += x + 0LL;
  }
  printf("%lld\n", cost);
}
