#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tests = 1;
  while (tests--) {
    long long int n;
    cin >> n;
    vector<long long int> v(2 * n);
    map<long long int, vector<long long int> > m;
    for (long long int i = 0; i < 2 * n; i++) {
      cin >> v[i];
      m[v[i]].push_back(i);
    }
    long long int a = 0, b = 0, i = 0, j = 0;
    for (long long int p = 1; p < n + 1; p++) {
      if (abs(m[p][0] - i) < abs(m[p][1] - i) &&
          abs(m[p][1] - j) < abs(m[p][0] - j)) {
        a += abs(m[p][0] - i);
        i = m[p][0];
        b += abs(m[p][1] - j);
        j = m[p][1];
      } else {
        b += abs(m[p][0] - j);
        j = m[p][0];
        a += abs(m[p][1] - i);
        i = m[p][1];
      }
    }
    cout << a + b;
  }
  return 0;
}
