// Arup Guha
// 2/22/2017
// Circle Cross USACO 2017 February Gold Problem: Why did the Cow Cross the Road III? (circlecross)

import java.util.*;
import java.io.*;

public class circlecross_gold {

	public static int n;
	public static int[] list;
	public static ArrayList[] iList;

	public static void main(String[] args) throws Exception {

		// Open file.
		BufferedReader stdin = new BufferedReader(new FileReader("circlecross.in"));
		n = Integer.parseInt(stdin.readLine().trim());
		list = new int[2*n];
		iList = new ArrayList[n];
		for (int i=0; i<n; i++) iList[i] = new ArrayList<Integer>();

		boolean[] isFirst = new boolean[2*n];
		boolean[] seen = new boolean[n];

		// Read in all the numbers, keeping track of the two indexes where each value shows up.
		for (int i=0; i<2*n; i++) {
			list[i] = Integer.parseInt(stdin.readLine().trim())-1;
			iList[list[i]].add(i);
			if (!seen[list[i]]) {
				isFirst[i] = true;
				seen[list[i]] = true;
			}
			else
				isFirst[i] = false;
		}

		// Does indexes 1 to 2n.
		bit myBit = new bit(2*n);

		long res = 0;

		// Loop through values.
		for (int i=0; i<2*n; i++) {

			// First time we are seeing this, add to bit.
			if (isFirst[i])
				myBit.add(i+1, 1L);

			// We've seen this, so we're closing an interval - add in the number of unique values in the interval.
			else {
				int val = list[i];
				int low = (Integer)(iList[val].get(0))+2;
				int high = (Integer)iList[val].get(1);
				myBit.add(low-1, -1L);
				res += myBit.sum(low, high);
			}
		}

		// Ta da!
		PrintWriter out = new PrintWriter(new FileWriter("circlecross.out"));
		out.println(res);
		out.close();
		stdin.close();
	}
}

class bit {

	public long[] cumfreq;

	// Do indexes 1 to n.
	public bit(int n) {

		int size = 1;
		while (size < n) size <<= 1;
		n = size;

		cumfreq = new long[n+1];
	}

	// Uses 1 based indexing.
	public void add(int index, long value) {
		while (index < cumfreq.length) {
			cumfreq[index] += value;
			index += Integer.lowestOneBit(index);
		}
	}

	// Returns the sum of everything upto index.
	public long sum(int index) {
		long ans = 0;
		while (index > 0) {
			ans += cumfreq[index];
			index -= (Integer.lowestOneBit(index));
		}
		return ans;
	}

	// Use 1 based indexing.
	public long sum(int low, int high) {
		return sum(high) - sum(low-1);
	}

	// Return the total number of items in the BIT.
	public long all() {
		return sum(cumfreq.length-1);
	}

	// Return the total number of items in the BIT at or above index.
	public long above(int index) {
		return all() - sum(index);
	}
}