import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static int p; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] base = new int[]{10, 9, 7, 5}; p = sc.nextInt(); int q = sc.nextInt(); int[] tmp = new int[n]; for (int i = 0; i < n; i++) { tmp[i] = sc.nextInt(); } Arrays.sort(tmp); int[][] values = new int[n][4]; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { values[i][j] = pow(base[j], tmp[i]); } } int ans = 0; for (int i = 0; i < n; i++) { int current1 = values[i][0]; for (int j = i + 1; j < n; j++) { int current2 = (current1 + values[j][1]) % p; for (int k = j + 1; k < n; k++) { int current3 = (current2 + values[k][2]) % p; for (int l = k + 1; l < n; l++) { int current4 = (current3 + values[l][3]) % p; if (current4 == q) { ans++; } } } } } System.out.println(ans); } static int pow(int x, int pp) { if (pp == 0) { return 1; } else if (pp % 2 == 0) { return pow((int)((long)x * x % p), pp / 2); } else { return (int)((long)pow(x, pp - 1) * x % p); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }