#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2e5 + 5, vector<int>(2));
  for (int i = 1; i <= 2 * n; i++) {
    int q;
    cin >> q;
    if (a[q][0] == 0)
      a[q][0] = i;
    else
      a[q][1] = i;
  }
  long long s = a[1][0] + a[1][1] - 2;
  for (int i = 2; i <= n; i++) {
    s += min(abs(a[i - 1][0] - a[i][0]) + abs(a[i - 1][1] - a[i][1]),
             abs(a[i - 1][1] - a[i][0]) + abs(a[i - 1][0] - a[i][1]));
  }
  cout << s;
}
