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

    int c = 0;
    int x = 0;
    for ( int a = 1 ; a < n + 1 ; a ++ )
    {
        for ( int b = 0 ; b < 2*n ; b ++ )
        {
            if ( asli[b] == a && c == 0 )
            {
                copy[a] = b;
                x = b;
                c ++;
            }

            else if ( asli[b] == a && c == 1 )
            {
                copy[a] = abs ( x - b );
            }
        }

        c = 0;
    }

    int sum = 0;
    for ( int i = 1 ; i < n + 1 ; i ++ )
    {
        sum += copy[i];
    }

    cout << sum;

    return 0;
}