AP and GP

5

1 votes
Standard template library (STL), Easy
Problem

You are given sorted arrays , and of size . You have to count the number of triplets (one number in each array) such that they are in for a given common ratio . Formally, number of indices , and such that ,  and are in and

Similarly, you have to count the number of triplets (one number in each array) such that they are in for a given common difference . Formally, number of indices , and such that ,  and are in and


Input:

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

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

Next 3 lines contains the array and respectively.


Output:

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


Constraints:

 ≤

, ,


Note: Consider are in GP.

Sample Input
6
2 2
1 2 2 3 4 7
2 3 4 5 6 8
2 3 4 5 7 8
Sample Output
3 3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The possible triplets in GP are:

The possible triplets in AP are:

Editor Image

?