In an array

Given an array of integers A(1 based indexing) of size N the ith integer of the array is A[i] and its value ranges between 1 and 1000 inclusive.
You are required to complete the following task:

You are provided with 3 additional numbers B, C, and D. Your task is to return the number of unordered pairs of elements (i,j) from this array, such that , (1 <= i < j <= N),(A[i] + A[j])%B = C and (A[i]xA[j])%B = D .

Note: As answer can be very large return answer % 10^9 + 7.


Input Format

The first argument given is the integer array A.
The second argument given is the integer B.
The third argument given is the integer C.
The fourth argument given is the integer D.

Output Format

Return the number of unordered pairs of elements (i,j) from this array, such that , (1 <= i < j <= N),(A[i] + A[j])%B = C and (A[i]xA[j])%B = D .

Constraints

1 <= N <= 10^5
1 <= B <= 10^6 
0 <= C, D <= 10^6 

For Example

Example Input 1:
    A = [1, 2, 3, 2, 1]
    B = 2
    C = 1
    D = 0
Example Output 1:
    6
Example Explanation 1:
    Required pairs are:-
    1. (1, 2)
    2. (1, 4)
    3. (2, 3)
    4. (2, 5)
    5. (3, 4)
    6. (4, 5)
    output = 6 % 10^9 + 7
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving In an array on Interview Code Editor
Sign Up
to access hints and editorial solutions for In an array

Discussion


Loading...
Click here to start solving coding interview questions