#include <bits/stdc++.h>
const long long minf = 1e+18;
const long long N = 200005;
const long double ep = 2.71828182845904523536;
using namespace std;
long long xd[100005][2];
bool aea[100005];
void useless() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  useless();
  long long n;
  cin >> n;
  for (long long i = 0; i < 2 * n; i++) {
    long long a;
    cin >> a;
    if (aea[a])
      xd[a][1] = i;
    else {
      xd[a][0] = i;
      aea[a] = true;
    }
  }
  long long resp = xd[1][0] + xd[1][1];
  for (long long i = 2; i <= n; i++) {
    resp += min(abs(xd[i][0] - xd[i - 1][0]) + abs(xd[i][1] - xd[i - 1][1]),
                abs(xd[i][1] - xd[i - 1][0]) + abs(xd[i][0] - xd[i - 1][1]));
  }
  cout << resp << endl;
  return 0;
}
