Count Matching Pairs
Given two arrays, A and B, of equal length N, find the number of pairs (i, j) such that A[i] == B[j]. Note that i and j can be the same or different, and an element from A can be matched with multiple elements from B, and vice-versa.
Input
The first line contains an integer N. The second line contains N space-separated integers representing array A. The third line contains N space-separated integers representing array B.
Output
A single integer representing the total count of matching pairs.
Constraints
1 <= N <= 200000. Each element in A and B is between -10^9 and 10^9.
Example 1
3 1 2 3 1 1 2
3
Pairs are (A[0], B[0]), (A[0], B[1]), (A[1], B[2]). Total 3 pairs.
Example 2
4 10 20 10 30 10 10 40 10
6
10 appears twice in A and thrice in B, contributing 2*3=6 pairs. 20 and 30 appear once in A but not in B. 40 appears once in B but not in A. Total 6 pairs.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
3 1 2 3 1 1 2
4 10 20 10 30 10 10 40 10