n = int(input())
n2 = n + n
ipt = input().split(' ')
arr = []
for i in range(n2):
arr.append(int(ipt[i]))
ans = 0
while len(arr) > 0:
first_item = arr.pop(0)
idx = arr.index(first_item)
ans += idx
arr.pop(idx)
print(ans)
n = int(input())
n2 = n + n
ipt = input().split(' ')
arr = []
for i in range(n2):
arr.append(int(ipt[i]))
ans = 0
while len(arr) > 0:
first_item = arr.pop(0)
idx = arr.index(first_item)
ans += idx
arr.pop(idx)
print(ans)