#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17 + 10;
const int N = 1e6 + 10;
const long long mod = 998244353;
const int base = 131;
const double pi = acos(-1);
map<string, int> ml;
map<int, int> mp;
map<int, int> vi;
priority_queue<pair<int, int> > q;
priority_queue<pair<int, int> > tq;
long long b[N], vis[N], dep[N], num[N], t, n, m, x, y, k;
long long ex, ey, cnt, ans, sum, flag;
vector<int> v[N];
struct node {
  int x, dex;
} f[N], s[N];
bool cmp(node a, node b) { return a.x < b.x; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n * 2; i++) {
    cin >> x;
    if (vis[x]) {
      f[++cnt2].x = x;
      f[cnt2].dex = i;
    } else {
      vis[x] = 1;
      s[++cnt1].x = x;
      s[cnt1].dex = i;
    }
  }
  sort(f + 1, f + cnt2 + 1, cmp);
  sort(s + 1, s + cnt2 + 1, cmp);
  f[0].dex = 1;
  s[0].dex = 1;
  for (int i = 1; i <= n; i++) {
    ans += abs(f[i].dex - f[i - 1].dex);
    ans += abs(s[i].dex - s[i - 1].dex);
  }
  cout << ans << endl;
}
