AP and GP

5

1 votes
Standard template library (STL), Easy
Problem

You are given 3 sorted arrays A, B and C of size N. You have to count the number of triplets (one number in each array) such that they are in GP for a given common ratio R. Formally, number of indices i, j and k such that A[i], B[j] and C[k] are in GP and (ijk)

Similarly, you have to count the number of triplets (one number in each array) such that they are in AP for a given common difference D. Formally, number of indices i, j and k such that A[i], B[j] and C[k] are in AP and (ijk)


Input:

First line contains an integer N, the size of the arrays. 

Next line contains two integers R and D, common ratio and common difference respectively.

Next 3 lines contains the array AB and C respectively.


Output:

In a single line print the number of triplets in GP and AP separated by a single space.


Constraints:

1 ≤ N105

0ArrayElements, R, D109


Note: Consider 0,0,0 are in GP.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The possible triplets in GP are:

[1,2,4],[2,4,8],[2,4,8]

The possible triplets in AP are:

[1,3,5],[3,5,7],[4,6,8]

Editor Image

?