#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     int f = 0, c = getchar();     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     if (f) x = -x;   }   template <typename T, typename... Args>   inline void read(T& x, Args&... args) {     read(x);     read(args...);   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   void writes(T x) {     write(x);     putchar(   );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   template <typename T>   inline bool chkmin(T& x, const T& y) {     return y < x ? (x = y, true) : false;   }   template <typename T>   inline bool chkmax(T& x, const T& y) {     return x < y ? (x = y, true) : false;   }   const int maxn = (int)3e5 + 10;   const long long inf = (long long)1e18;   const int mod = (int)1e9 + 7;   int n, a[maxn];   long long ans;   vector<int> v[maxn];   int main() {     read(n);     for (int i = (1); i < (2 * n + 1); i++) read(a[i]);     for (int i = (1); i < (2 * n + 1); i++) {       v[a[i]].push_back(i);     }     int now = 1;     for (int i = (1); i < (n + 1); i++) {       ans += abs(v[i][0] - now);       now = v[i][0];     }     now = 1;     for (int i = (1); i < (n + 1); i++) {       ans += abs(v[i][1] - now);       now = v[i][1];     }     write(ans);   }   