#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, a[MAXN];
vector<int> pos[MAXN];
int main() {
  n = read();
  for (int i = 1; i <= 2 * n; i++) {
    a[i] = read();
    pos[a[i]].push_back(i);
  }
  long long dis = pos[1][0] + pos[1][1] - 2;
  for (int i = 2; i <= n; i++) {
    int d11 = abs(pos[i - 1][0] - pos[i][0]);
    int d12 = abs(pos[i - 1][0] - pos[i][1]);
    int d21 = abs(pos[i - 1][1] - pos[i][0]);
    int d22 = abs(pos[i - 1][1] - pos[i][1]);
    dis += min(d12 + d21, d11 + d22);
  }
  cout << dis;
  return 0;
}
