#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int mod = (int)1e9 + 7;
using namespace std;
int p[N][2];
int check(int id, int x, int i, int y, int j) {
  return abs(x - p[id][i]) + abs(y - p[id][j]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int x;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> x;
    if (!p[x][0])
      p[x][0] = i;
    else
      p[x][1] = i;
  }
  int y;
  long long ans = 0;
  x = y = 1;
  for (int i = 1; i <= n; i++) {
    int pos = (check(i, x, 0, y, 1) > check(i, x, 1, y, 0));
    ans += check(i, x, pos, y, 1 ^ pos);
    x = p[i][pos];
    y = p[i][pos ^ 1];
  }
  cout << ans;
  return 0;
}
