#include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const int MAX = 1e7 ; int MOD = 998244353 ; long long fac[MAX], finv[MAX], inv[MAX]; ll D[205][100005] ; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 nCk long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 順列計算 nPk = n! / ( ( n - k ) ! ) long long PER(int n , int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return ( fac[n] * finv[n-k] ) % MOD ; } // べき乗計算 ll POW(ll a, ll n ) { if (n == 0) return 1; if (n == 1) return a % MOD; if (n % 2 == 1) return (a * POW(a, n - 1 )) % MOD; ll t = POW(a, n / 2 ); return (t * t) % MOD ; } int main(){ ll n , p , q ; cin >> n >> p >> q ; MOD = p ; vector A(n) ; rep(i,n) cin >> A[i] ; sort(A.begin(),A.end()) ; //reverse(A.begin(),A.end()) ; rep(j,n){ D[j][POW(5,A[j])]++; } for( ll j = n - 1 ; j > 0 ; j-- ){ rep(i,100005){ D[j-1][i] += D[j][i] ; } } ll ans = 0 ; for( ll a = 0 ; a < n ; a++ ){ for( ll b = a + 1 ; b < n ; b++ ){ for( ll c = b + 1 ; c < n ; c++ ){ ll tmp = POW(10,A[a])+POW(9,A[b])+POW(7,A[c]) ; tmp %= MOD ; tmp = ( q - tmp + MOD ) % MOD ; ans += D[c+1][tmp] ; } } } cout << ans << endl ; }