PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000226. Đếm cặp có tổng và hiệu chia hết (Divisible Pairs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm cặp có tổng và hiệu chia hết (Divisible Pairs)

Divisible Pairs

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array a1,…,ana_1,\ldots,a_n and positive integers x,yx,y, count index pairs 1≤i<j≤n1\le i<j\le n satisfying both x∣(ai+aj)x\mid(a_i+a_j) and y∣(ai−aj)y\mid(a_i-a_j). Divisibility is defined for integers, including negative differences. Count each pair once.

Input

First line contains n,x,yn,x,y; second line has nn integers aia_i.

Output

Print the number of valid index pairs.

Subtasks

  • Subtask 1 (20 points): 2≤n≤100, 1≤x,y,ai≤10002\le n\le 100,\ 1\le x,y,a_i\le 1000.

  • Subtask 2 (30 points): 2≤n≤5000, 1≤x,y,ai≤10000002\le n\le 5000,\ 1\le x,y,a_i\le 1000000.

  • Subtask 3 (50 points): 2≤n≤200000, 1≤x,y,ai≤10000000002\le n\le 200000,\ 1\le x,y,a_i\le 1000000000.

Examples

Example 1

Input

6 5 2
1 2 7 4 9 6

Output

2

Explanation

The valid index pairs are (1,5), with sum 10 and difference -8, and (4,6), with sum 10 and difference -2.

Example 2

Input

3 1 1
2 2 2

Output

3

Explanation

Every pair of distinct indices qualifies: (32)=3\binom{3}{2}=3.