#include <bits/stdc++.h>
int __gcd(int a, int b) { return b ? __gcd(b, a % b) : a; }
using namespace std;
const int N = 100100;
int main() {
  int i, n, len, t;
  long long ans = 0;
  scanf("%d", &n);
  vector<int> x(2 * n, 0);
  vector<vector<int>> m(2 * n + 1);
  int neg = 0, pos = 0;
  for (i = 0; i < 2 * n; i++) {
    scanf("%d", &x[i]);
    m[x[i]].push_back(i + 1);
  }
  int le = 1, ri = 1;
  for (auto i = 1; i <= n; i++) {
    auto fi = m[i][0], se = m[i][1];
    auto a = abs(le - fi);
    auto b = abs(le - se);
    auto c = abs(ri - fi);
    auto d = abs(ri - se);
    if (a + d < b + c) {
      ans += (a + d);
      le = fi;
      ri = se;
    } else {
      ans += (b + c);
      le = se;
      ri = fi;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
