#include using namespace std; #include using mint = atcoder::modint998244353; #define int long long signed main() { int n,p,q; cin >> n >> p >> q; int m = 2e6+1; vector a(m,1), b(m,1), c(m,1), d(m,1); for(int i = 0; i < m-1; i++) { a[i+1] = a[i]*10%p; b[i+1] = b[i]*9%p; c[i+1] = c[i]*7%p; d[i+1] = d[i]*5%p; } vector e(n,0); vector> f(p); for(int i = 0; i < n; i++) { cin >> e[i]; f[d[e[i]]].push_back(i); } int ans = 0; for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) for(int k = j+1; k < n; k++) { int z = (a[e[i]]+b[e[j]]+c[e[k]])%p; z = (q-z+p)%p; int g = f[z].end()-upper_bound(f[z].begin(),f[z].end(),k); ans+=g; } cout << ans << endl; }