#include <bits/stdc++.h>
using namespace std;
const int _N = 1e5 + 7;
int A[_N], B[_N][2], N;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N * 2; ++i) {
    int x;
    scanf("%d", &x);
    if (B[x][0])
      B[x][1] = i;
    else
      B[x][0] = i;
  }
  long long ans = 0;
  for (int i = 1; i <= N; ++i) {
    int a = abs(B[i][0] - B[i - 1][0]) + abs(B[i][1] - B[i - 1][1]);
    int b = abs(B[i][1] - B[i - 1][0]) + abs(B[i][0] - B[i - 1][1]);
    ans += min(a, b);
  }
  printf("%I64d\n", ans - 2);
  return 0;
}
