use std::io::{self, BufRead}; fn main() { let stdin = io::stdin(); let mut stdin_lock = stdin.lock(); let mut line = String::new(); stdin_lock.read_line(&mut line).unwrap(); let mut n_p_q = line.trim().split_whitespace().map(|x| x.parse::().unwrap()); let n = n_p_q.next().unwrap(); let p = n_p_q.next().unwrap(); let q = n_p_q.next().unwrap(); line.clear(); stdin_lock.read_line(&mut line).unwrap(); let mut a: Vec = line.trim().split_whitespace().map(|x| x.parse::().unwrap()).collect(); a.sort(); let mut ans = 0; for i in 0..n { for j in i + 1..n { for k in j + 1..n { for l in k + 1..n { let a_i = a[i]; let b = a[j]; let c = a[k]; let d = a[l]; if (mod_pow(10, a_i, p) + mod_pow(9, b, p) + mod_pow(7, c, p) + mod_pow(5, d, p)) % p == q { ans += 1; } } } } } println!("{}", ans); } fn mod_pow(mut base: usize, mut exp: usize, modulus: usize) -> usize { let mut result = 1; base %= modulus; while exp > 0 { if exp % 2 == 1 { result = (result * base) % modulus; } exp >>= 1; base = (base * base) % modulus; } result }