import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static int[][] values; static int[] base = new int[]{10, 9, 7, 5}; static int[][][] dp; static int p; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); 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); 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]); } } dp = new int[n][p][4]; for (int[][] arr1 : dp) { for (int[] arr2 : arr1) { Arrays.fill(arr2, -1); } } System.out.println(dfw(n - 1, (p - q) % p, 3)); } static int dfw(int idx, int v, int w) { if (w < 0) { if (v == 0) { return 1; } else { return 0; } } if (idx < 0) { return 0; } if (dp[idx][v][w] < 0) { dp[idx][v][w] = dfw(idx - 1, v, w) + dfw(idx - 1, (v + values[idx][w]) % p, w - 1); } return dp[idx][v][w]; } 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(); } } }