import std, core.bitop; bool chmin(T)(ref T SE, T MI) { if (SE > MI) { SE = MI; return true; } else { return false; } } bool chmax(T)(ref T SE, T MI) { if (SE < MI) { SE = MI; return true; } else { return false; } } int lowerBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] < MI ? lo : hi) = mid; } return hi; } int upperBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] > MI ? hi : lo) = mid; } return hi; } void main() { int N, P, Q; readf("%s %s %s\n", N, P, Q); auto A = readln.chomp.split.to!(int[]); A.sort; enum semi = 2020202; auto p10 = new int[semi]; p10[0] = 1; foreach (i; 1 .. semi) { p10[i] = p10[i - 1] * 10 % P; } auto p9 = new int[semi]; p9[0] = 1; foreach (i; 1 .. semi) { p9[i] = p9[i - 1] * 9 % P; } auto p7 = new int[semi]; p7[0] = 1; foreach (i; 1 .. semi) { p7[i] = p7[i - 1] * 7 % P; } auto p5 = new int[semi]; p5[0] = 1; foreach (i; 1 .. semi) { p5[i] = p5[i - 1] * 5 % P; } auto cnt = new int[P]; foreach (i; 0 .. N) { ++cnt[p5[A[i]]]; } int ans; foreach (i; 0 .. N) { --cnt[p5[A[i]]]; foreach (j; 0 .. i) { foreach (k; 0 .. j) { ans += cnt[(Q - (p10[A[k]] + p9[A[j]] + p7[A[i]]) % P + P) % P]; } } } ans.writeln; }