#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int asli[2*n] , copy[2*n];
    for ( int i = 0 ; i < 2*n ; i ++ )
    {
        cin >> asli[i];
        copy[i] = i;
    }

    for ( int a = 0 ; a < 2*n ; a ++ )
    {
        for ( int b = 0 ; b < 2*n ; b ++ )
        {
            if ( asli[b] < asli[a] && b > a )
            {
                swap ( asli[a] , asli[b] );
                swap ( copy[a] , copy[b] );
            }
        }
    }


    int sum = 0;
    int i = 0;
    while ( i < 2*n )
    {
        sum += abs ( copy[i + 1] - copy[i] );
        i = i + 2;
    }
    
   cout << sum;

    return 0;
}