#include <bits/stdc++.h>
using namespace std;
int amount;
vector<int> position[100005];
int main() {
  scanf("%d", &amount);
  for (int i = 1; i <= 2 * amount; i++) {
    int cake;
    scanf("%d", &cake);
    position[cake].push_back(i);
  }
  int alpha = 1, belta = 1;
  long long total = 0;
  for (int i = 1; i <= amount; i++) {
    total += abs(position[i][0] - alpha);
    total += abs(position[i][1] - belta);
    alpha = position[i][0];
    belta = position[i][1];
  }
  printf("%lld", total);
}
