#include <bits/stdc++.h>
using namespace std;
int n, a[200010], pos[200010][3], tag[200010][3];
long long ans, num1, num2, cnt1, cnt2;
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n * 2; i++) {
    scanf("%d", &a[i]);
    pos[a[i]][0]++;
    pos[a[i]][pos[a[i]][0]] = i;
  }
  pos[0][1] = pos[0][2] = 1;
  for (i = 1; i <= n; i++) {
    cnt1 = fabs(pos[i][1] - pos[i - 1][1]) + fabs(pos[i][2] - pos[i - 1][2]);
    cnt2 = fabs(pos[i][1] - pos[i - 1][2]) + fabs(pos[i][2] - pos[i - 1][1]);
    if (cnt1 < cnt2)
      ans += cnt1;
    else
      ans += cnt2;
  }
  printf("%I64d\n", ans);
  return 0;
}
