#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  map<long long, vector<long long>> m;
  for (long long i = 0; i < 2 * n; i++) {
    long long tmp;
    cin >> tmp;
    try {
      m.at(tmp).push_back(i);
    } catch (...) {
      m[tmp] = {i};
    }
  }
  long long curS = 0;
  long long curD = 0;
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    vector<long long> tmp = m.at(i);
    sort(tmp.begin(), tmp.end());
    ans += abs(curS - tmp.at(0));
    ans += abs(curD - tmp.at(1));
    curS = tmp.at(0);
    curD = tmp.at(1);
  }
  cout << ans << '\n';
  return 0;
}
