Quokkas and Koalas

Program time limit: 1 second

Program memory limit: 512 MB

At Quokkas and Koalas Love Society, your members are mingling based on how much they like Quokkas and Koalas.

Each member has a value $Q_i$ which indicates how much they like Quokkas and a value $K_i$ which indicates how much they like Koalas. Two members $i$ and $j$ have a Quokka love coefficient of $Q_i \cdot Q_j$ and a Koala love coefficient of $K_i \cdot K_j$. Two members are friends if these coefficients are equal.

Output how many pairs of friends there are.

Input

  • The first line of input contains an integer $N$, representing the number of members.
  • The second line contains $N$ space separated integers, representing $Q_1, Q_2, \ldots, Q_N$.
  • The third line contains $N$ space separated integers, representing $K_1, K_2, \ldots, K_N$.

Constraints

For all test cases:

  • $1 \le N \le 100,000$,
  • $0 \le Q_i, K_i \le 1,000,000,000$ for $1 \le i \le N$.

Output

  • Output a single integer, which represents the number of pairs of friends.

Templates

You should read from standard input and write to standard output.

In Python, you could use the following code.

# Taking inputs, already done! :D
N = int(input())
Q = list(map(int, input().split()))
K = list(map(int, input().split()))

ans = 0
# Write your code here


# Printing output
print(ans)

In C or C++, you could use the following code.

// Taking inputs, already done! :D
int N; scanf("%d", &N);
long long Q[N]; for (int i = 0; i < N; i++) scanf("%lld", &Q[i]);
long long K[N]; for (int i = 0; i < N; i++) scanf("%lld", &K[i]);

long long ans;
// Write your code here


// Printing output
printf("%lld\n", ans);

Sample Input 1

6
1 2 2 5 5 6
1 1 4 0 5 4

Sample Output 1

2

Explanation 1

We need to find pairs $(i,j)$ where $Q_i \cdot Q_j = K_i \cdot K_j$.

For members 1 and 5, $Q_1 \cdot Q_5 = 1 \cdot 5 = 5$ and $K_1 \cdot K_5 = 1 \cdot 5 = 5$ so they are friends. For members 2 and 3, $Q_2 \cdot Q_3 = 2 \cdot 2 = 4$ and $K_2 \cdot K_3 = 1 \cdot 4 = 4$ so they are also friends. These are our only pairs of friends, so the answer is $2$.

Sample Input 2

3
2 3 0
3 2 0

Sample Output 2

3

Explanation 2

All three pairs are friends, so the answer is $3$.

Scoring

Your program will be run on both sample cases and 7 secret cases one after another, and if it produces the correct output for all test cases, it solves this task. Recall that your final score on the task is the score of your highest scoring submission.


Submit

Log in to submit!