#include <bits/stdc++.h>
using namespace std;
int N;
int cp[100000 + 10][2];
long long int ans[100000 + 10];
int dist(int i, int j) { return (i > j) ? (i - j) : (j - i); }
int main() {
  scanf("%d", &N);
  memset(cp, -1, sizeof cp);
  int tmp;
  for (int i = 1; i <= 2 * N; i++) {
    scanf("%d", &tmp);
    if (cp[tmp][0] == -1)
      cp[tmp][0] = i;
    else
      cp[tmp][1] = i;
  }
  ans[0] = 0;
  cp[0][0] = cp[0][1] = 1;
  for (int i = 1; i <= N; i++) {
    ans[i] = ans[i - 1] +
             min(dist(cp[i - 1][0], cp[i][0]) + dist(cp[i - 1][1], cp[i][1]),
                 dist(cp[i - 1][0], cp[i][1]) + dist(cp[i - 1][1], cp[i][0]));
  }
  printf("%lld\n", ans[N]);
}
