#!/usr/bin/python3 import bisect import collections import heapq import itertools import math import os import sys B = (10, 9, 7, 5) def main(): n, p, q = read_ints() A = read_ints() A.sort() P = list2d(4, n) for c in range(4): for i in range(n): P[c][i] = pow(B[c], A[i], p) print(rec(n, p, q, P, 0, 0, 0)) def rec(n, p, q, P, i, c, s): if c == 4: if s == q: return 1 return 0 ans = 0 for j in range(i, n - (3 - c)): ans += rec(n, p, q, P, j + 1, c + 1, (s + P[c][j]) % p) return ans ############################################################################### DEBUG = 'DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def list2d(d1, d2, init=None): return [[init] * d2 for _ in range(d1)] def list3d(d1, d2, d3, init=None): return [[[init] * d3 for _ in range(d2)] for _ in range(d1)] def list4d(d1, d2, d3, d4, init=None): return [[[[init] * d4 for _ in range(d3)] for _ in range(d2)] for _ in range(d1)] def debug(fmt, *args): if DEBUG: if args: print(fmt.format(*args), file=sys.stderr) else: print(fmt, file=sys.stderr) if __name__ == '__main__': main()