#include #include using namespace std;using namespace atcoder;using vst = vector;using ll = long long; using ld = long double;using pll = pair;using vll = vector;using vvll = vector; using vpll = vector; #define rep(i, n) for (ll i = 0; i < n; i++) #define repp(i,k,n) for (ll i = k; i < n; i++) #define per(i,s,e) for(ll i = s; i >= e; i--) #define all(v) v.begin(),v.end() #define no() {cout << "No" << endl; return 0;} #define yes(){cout << "Yes" << endl;return 0;} #define yesno(a) a ? cout << "Yes" << endl : cout << "No" << endl #define YESNO(a) a ? cout << "YES" << endl : cout << "NO" << endl #define MODD 998244353LL #define MOD 1000000007LL #define UNOmap unordered_map #define UNOset unordered_set #define ASC(T) T,vector,greater #define join(G,a,b) G[a].push_back(b);G[b].push_back(a); #define PB(a,b) a.push_back(b) templatevoid in(T&... a){(cin >> ... >> a);} templatevoid out(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << '\n';} void vin(vll &v){for(ll i = 0; i < (ll)v.size(); i++)in(v[i]);} void vout(vll &v){for(ll i = 0; i < (ll)v.size(); i++) cout << v[i] << ' ';cout << "\n";} ll INF = 1LL << 62; // #include // using namespace boost::multiprecision; // using mint = modint998244353; // using mint = modint1000000007; // using mint = modint; // cout << fixed << setprecision(15); //---------------------------------------------- int main(){ ll N,P,Q; in(N,P,Q); vll A(N); vin(A); ll ans = 0; vvll p(2e6+9,vll(4)); ll p10,p9,p7,p5; p10 = 1; p9 = 1; p7 = 1; p5 = 1; rep(i,2e6+9){ p[i][0] = p10%P; p[i][1] = p9%P; p[i][2] = p7%P; p[i][3] = p5%P; p10 *= 10; p9 *= 9; p7 *= 7; p5 *= 5; } rep(i,N){ rep(j,i){ rep(k,j){ rep(l,k){ ll d = A[i]; ll c = A[j]; ll b = A[k]; ll a = A[l]; ll cur = 0; cur += p[a][0]; cur += p[b][1]; cur += p[c][2]; cur += p[d][3]; cur %= P; if(cur == Q) ans++; } } } } out(ans); }