#include #include using namespace std; using namespace atcoder; #define overload5(a,b,c,d,e,name,...) name #define overload4(a,b,c,d,name,...) name #define overload3(a,b,c,name,...) name #define rep1(n) for(ll i=0;i=(b);--i) #define rrep4(i,a,b,c) for(ll i=a;i>=(b);i-=c) #define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__) #define ALL1(i) begin(i),end(i) #define ALL2(i,a) begin(i),begin(i)+a #define ALL3(i,a,b) begin(i)+a,begin(i)+b #define ALL(...) overload3(__VA_ARGS__,ALL3,ALL2,ALL1)(__VA_ARGS__) #define sz(a) ((ll)a.size()) #define lb(v, x) distance((v).begin(), lower_bound(ALL(v), (x))) #define lbg(v, x) distance((v).begin(), lower_bound(ALL(v), (x), greater{})) #define ub(v, x) distance((v).begin(), upper_bound(ALL(v), (x))) #define ubg(v, x) distance((v).begin(), upper_bound(ALL(v), (x), greater{})) #define SORT(v) sort(ALL(v)) #define RSORT(v) sort(rbegin(v),rend(v)) #define REV(v) reverse(ALL(v)) using ll = long long; using P = pair; using vb = vector; using vvb = vector; using vc = vector; using vvc = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vl = vector; using vvl = vector; using vvvl = vector; using vvvvl = vector; using vd = vector; using vvd = vector; using vp = vector

; using vvp = vector; using vs = vector; using vvs = vector; constexpr ll zero=0; constexpr ll LINF=2e18; constexpr ll INF=1001001001; constexpr int dx[8]={-1,0,1,0,-1,1,1,-1}; constexpr int dy[8]={0,1,0,-1,1,1,-1,-1}; template inline bool chmax(T1 &a, T2 b) {return ((a < b) ? (a = b, true) : (false));} template inline bool chmin(T1 &a, T2 b) {return ((a > b) ? (a = b, true) : (false));} template bool inRange(const T &x, const T &l, const T &r) {return l <= x & x < r;} constexpr ll div_floor(ll x, ll y) {assert(y != 0); return (x - ((x%y+y)%y)) / y;} constexpr ll div_ceil(ll x, ll y) {assert(y != 0); return (x + ((y-x%y)%y)) / y;} using mint = modint998244353; vvl To(ll n, ll m, bool directed = false) { vvl to(n); while(m--) { ll u, v; cin >> u >> v; u--, v--; to[u].push_back(v); if(!directed) to[v].push_back(u); } return to; } vvp ToW(ll n, ll m, bool directed = false) { vvp to(n); while(m--) { ll u, v, w; cin >> u >> v >> w; u--, v--; to[u].emplace_back(v, w); if(!directed) to[v].emplace_back(u, w); } return to; } int main() { ll n, p, q; cin >> n >> p >> q; vl a(n); rep(i,n) cin >> a[i]; SORT(a); vl a10(n), a9(n), a7(n), a5(n); rep(i,n) { a10[i] = pow_mod(10,a[i],p); a9[i] = pow_mod(9,a[i],p); a7[i] = pow_mod(7,a[i],p); a5[i] = pow_mod(5,a[i],p); } ll ans = 0; rep(i,n) { rep(j,i+1,n) { rep(k,j+1,n) { rep(l,k+1,n) { ll sum = a10[i] + a9[j] + a7[k] + a5[l]; if(sum % p == q) { ans++; } } } } } cout << ans << endl; return 0; }