#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265;
void fastInOut();
const int N = 100005;
vector<int> v[N];
int main() {
  fastInOut();
  int n, x;
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    cin >> x;
    v[x].push_back(i);
  }
  int idx = 1, a = v[idx][0], b = v[idx][1];
  long long res = a + b;
  idx++;
  while (idx <= n) {
    int c1 = abs(a - v[idx][0]) + abs(b - v[idx][1]),
        c2 = abs(a - v[idx][1]) + abs(b - v[idx][0]);
    if (c1 < c2) {
      res += c1;
      a = v[idx][0];
      b = v[idx][1];
    } else {
      res += c2;
      a = v[idx][1];
      b = v[idx][0];
    }
    idx++;
  }
  cout << res;
  return 0;
}
void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
