#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int arr1[2*n] , arr2[n + 1];
    arr2[0] = 0;
    int c = 1;
    for ( int i = 0 ; i < 2*n ; i ++ )
    {
        cin >> arr1[i];
        if ( arr1[i] == c )
        {
            arr2[c] = i;
            c ++;
        }
    }

    int a = 0;
    int b = 1;
    int sum = 0;
    while ( a < 2*n )
    {
        if ( b == arr1[a] && arr2[b] != a && b <= n )
        {
            sum += abs ( arr2[b] - a );
            b ++;
        }

        a ++;
    }

    cout << sum;
    
    return 0;
}