#include <bits/stdc++.h>
using namespace std;
vector<long long> house[200010];
void FAST_IO();
int main() {
  int n, temp;
  cin >> n;
  for (long long int i = 1; i <= 2 * n; i++) {
    cin >> temp;
    house[temp].push_back(i);
  }
  long long int total = 0;
  total += house[1][0] + house[1][1] - 2;
  for (long long int i = 2; i <= n; i++) {
    total +=
        abs(house[i][0] - house[i - 1][0]) + abs(house[i][1] - house[i - 1][1]);
  }
  cout << total << endl;
  return 0;
}
void FAST_IO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
