/* */ #include using namespace std; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int main(){ int n; ll p, q; cin >> n >> p >> q; vector A(n); rep(i, n){ cin >> A[i]; } sort(A.begin(), A.end()); vector a(4); int ans = 0; rep(i, n){ //200 // cout << "i: " << i << endl; rep(j, n-4){ ll x = 0; // cout << "j: " << j << endl; int add = 0; if(i == 0){ add = j+1; }else{ add = j; } int cnt = 0; while(cnt < 4){ if(add != i){ a[cnt] = A[add]; cnt++; // cout << add << ' '; } add++; } ll t = 1; rep(j_, a[0]) t *= 10; x += t; t = 1; rep(j_, a[1]) t*= 9; x += t; t = 1; rep(j_, a[2]) t*= 7; x += t; t = 1; rep(j_, a[3]) t*= 5; x += t; // cout << x << endl; if(x % p == q){ // rep(i, 4){ // cout << a[i] << ' '; // }a // cout << endl; // cout << "x: " << x << endl; ans++; } // cout << endl; } } cout << ans << endl; return 0; }