#include <bits/stdc++.h>
using namespace std;
map<int, int> mp[2];
int p[2];
long long n, c, out, a;
int main() {
  cin >> n;
  for (int i = 0; i < n * 2; i++) {
    cin >> c;
    if (mp[0].find(c) == mp[0].end()) {
      mp[0][c] = i;
    } else {
      mp[1][c] = i;
    }
  }
  p[0] = mp[0][1];
  p[1] = mp[1][1];
  out += mp[0][1] + mp[1][1];
  for (int i = 2; i <= n; i++) {
    if (abs(mp[0][i] - p[1]) + abs(mp[1][i] - p[0]) <=
        abs(mp[0][i] - p[0]) + abs(mp[1][i] - p[1])) {
      out += abs(mp[0][i] - p[1]) + abs(mp[1][i] - p[0]);
      p[1] = mp[0][i];
      p[0] = mp[1][i];
    } else {
      out += abs(mp[0][i] - p[0]) + abs(mp[1][i] - p[1]);
      p[0] = mp[0][i];
      p[1] = mp[1][i];
    }
  }
  cout << out;
  return 0;
}
