#include <bits/stdc++.h>
const long long int M = 1e9 + 7;
using namespace std;
long long int N = 200000;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  map<long long int, vector<long long int>> mp;
  for (long long int i = 0; i < 2 * n; i++) {
    long long int a;
    cin >> a;
    mp[a].push_back(i + 1);
  }
  long long int pa = 1, push_back = 1, r = 1;
  long long int ans = 0;
  while (true) {
    if ((abs(pa - mp[r][0]) + abs(push_back - mp[r][1])) >
        (abs(pa - mp[r][1]) + abs(push_back - mp[r][0]))) {
      ans += (abs(pa - mp[r][1]) + abs(push_back - mp[r][0]));
      pa = mp[r][1];
      push_back = mp[r][0];
    } else {
      ans += (abs(pa - mp[r][0]) + abs(push_back - mp[r][1]));
      pa = mp[r][0];
      push_back = mp[r][1];
    }
    r++;
    if (r == n + 1) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
