#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Read, Write, BufWriter};
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

mod pollard_rho {
    use std::collections::HashMap;
    /// binary gcd
    pub fn gcd(mut x: i64, mut y: i64) -> i64 {
        if y == 0 { return x; }
        if x == 0 { return y; }
        let mut sh = 0;
        while ((x | y) & 1) == 0 {
            x >>= 1; y >>= 1; sh += 1;
        }
        while (x & 1) == 0 { x >>= 1; }
        while y != 0 {
            while (y & 1) == 0 { y >>= 1; }
            if x > y { let t = x; x = y; y = t; }
            y -= x;
        }
        x << sh
    }

    fn add_mod(x: i64, y: i64, n: i64) -> i64 {
        let z = x + y;
        if z >= n { z - n } else { z }
    }

    fn mul_mod(x: i64, mut y: i64, n: i64) -> i64 {
        assert!(x >= 0);
        assert!(x < n);
        let mut sum = 0;
        let mut cur = x;
        while y > 0 {
            if (y & 1) == 1 {
                sum = add_mod(sum, cur, n);
            }
            cur = add_mod(cur, cur, n);
            y >>= 1;
        }
        sum
    }

    fn mod_pow(x: i64, mut e: i64, n: i64) -> i64 {
        let mut prod = if n == 1 { 0 } else { 1 };
        let mut cur = x % n;
        while e > 0 {
            if (e & 1) == 1 {
                prod = mul_mod(prod, cur, n);
            }
            cur = mul_mod(cur, cur, n);
            e >>= 1;
        }
        prod
    }

    pub fn is_prime(n: i64) -> bool {
        if n <= 1 { return false; }
        let small = [2, 3, 5, 7, 11, 13];
        if small.iter().any(|&u| u == n) { return true; }
        if small.iter().any(|&u| n % u == 0) { return false; }
        let mut d = n - 1;
        let mut e = 0;
        while (d & 1) == 0 {
            d >>= 1;
            e += 1;
        }
        let a = [2, 325, 9375, 28178, 450775, 9780504, 1795265022];
        a.iter().all(|&a| {
            if a >= n { return true; }
            let mut x = mod_pow(a, d, n);
            if x == 1 { return true; }
            for _ in 0 .. e {
                if x == n - 1 {
                    return true;
                }
                x = mul_mod(x, x, n);
                if x == 1 { return false; }
            }
            x == 1
        })
    }

    fn pollard_rho(n: i64, c: &mut i64) -> i64 {
        if n % 2 == 0 { return 2; }
        loop {
            let mut x: i64 = 2;
            let mut y = 2;
            let mut d = 1;
            let cc = *c;
            let f = |i| add_mod(mul_mod(i, i, n), cc, n);
            while d == 1 {
                x = f(x);
                y = f(f(y));
                d = gcd((x - y).abs(), n);
            }
            if d == n {
                *c += 1;
                continue;
            }
            return d;
        }
    }

    /// Outputs (p, e) in p's ascending order.
    pub fn factorize(x: i64) -> Vec<(i64, usize)> {
        if x <= 1 {
            return Vec::new();
        }
        let mut hm = HashMap::new();
        let mut pool = vec![x];
        let mut c = 1;
        while let Some(u) = pool.pop() {
            if is_prime(u) {
                *hm.entry(u).or_insert(0) += 1;
                continue;
            }
            let p = pollard_rho(u, &mut c);
            pool.push(p);
            pool.push(u / p);
        }
        let mut v: Vec<_> = hm.into_iter().collect();
        v.sort();
        v
    }
} // mod pollard_rho

/// Generates an Iterator over subsets of univ, in the descending order.
/// Verified by: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3050308
struct SubsetIter { bits: Option<usize>, univ: usize }
impl Iterator for SubsetIter {
    type Item = usize;
    fn next(&mut self) -> Option<usize> {
        match self.bits {
            None => None,
            Some(bits) => {
                let ans = bits;
                self.bits =
                    if bits == 0 { None }
                else { Some((bits - 1) & self.univ) };
                Some(ans)
            }
        }
    }
}
fn subsets(univ: usize) -> SubsetIter {
    SubsetIter { bits: Some(univ), univ }
}

use pollard_rho::*;

fn solve() {
    let n = get();
    let x: i64 = get();
    let y: i64 = get();
    if y % x != 0 {
        println!("0");
        return;
    }
    let a: Vec<i64> = (0 .. n).map(|_| get()).collect();
    let b: Vec<i64> = a.iter().filter_map(|&a| if a % x == 0 { Some(a / x) } else { None }).collect();
    let c: Vec<i64> = a.iter().filter_map(|&a| if y % a == 0 { Some(y / a) } else { None }).collect();
    let y = y / x;
    let fac = factorize(y);
    let m = fac.len();
    let mut pat1 = vec![0i64; 1 << m];
    let mut pat2 = vec![0i64; 1 << m];
    for &b in &b {
        let mut hot = 0;
        for i in 0 .. m {
            let p = fac[i].0;
            if b % p == 0 {
                hot |= 1 << i;
            }
        }
        pat1[hot] += 1;
    }
    for &c in &c {
        let mut hot = 0;
        for i in 0 .. m {
            let p = fac[i].0;
            if c % p == 0 {
                hot |= 1 << i;
            }
        }
        pat2[hot] += 1;
    }
    let mut ans = 0;
    for bits in 0 .. 1 << m {
        for opp in subsets((1 << m) - 1 - bits) {
            ans += pat1[bits] * pat2[opp];
        }
    }
    println!("{}", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::*;
#[allow(unused_imports)] use std::collections::*;

#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}

#[allow(dead_code)]
fn build_counting_hashmap<K: Eq + std::hash::Hash, T>(i: T) -> HashMap<K,usize>
    where T: Iterator<Item = K> {
    let mut m = HashMap::new();
    for k in i {
        let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };
        m.insert(k, n);
    }
    m
}

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let mut a: i64 = input.p();
    let mut b: i64 = input.p();
    let mut sol = 0;
    while b > 0 {
        sol += a / b;
        let t = a % b;
        a = b;
        b = t;
    }
    println!("{}", sol);
}


#[allow(unused_imports)]
use std::cmp::{max,min};
#[allow(unused_imports)]
use std::collections::{HashMap,HashSet,VecDeque};

#[allow(unused_macros)]
macro_rules! readln {
    () => {{
        use std::io;

        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

#[allow(unused_macros)]
macro_rules! readvec {
    ( $t:ty ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        let mut result = Vec::new();
        for elem in input {
            result.push(elem.parse::<$t>().unwrap());
        }
        result
    }}
}

fn gcd(a: i64, b: i64) -> i64 {
  if a > b {
    return gcd(b,a);
  }
  if a == 0 {
    return 0;
  } else {
    return (b/a) + gcd(b%a,a);
  }
}

fn main() {
  let (a,b) = readln!(i64,i64);
  let res = gcd(a,b);
  println!("{}",res);
}


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

    fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next::<T>()).collect()
    }
}

fn gcd(a: usize, b: usize) -> usize {
    let mut x = a;
    let mut y = b;
    let mut tmp = 0usize;
    while x > 0 {
        tmp = x;
        x = y % x;
        y = tmp;
    }
    y
}

fn _main() {
    let mut scan = Scan::new();
    let a: usize = scan.next();
    let b: usize = scan.next();
    let c: usize = scan.next();
    let d: usize = scan.next();
    let mut p = 0usize;
    let mut q = 0usize;
    if a * d >= c * b {
        p = c * b;
        q = a * d;
    } else {
        p = d * a;
        q = b * c;
    }
    p = q - p;
    let m = gcd(p, q);
    p = p / m;
    q = q / m;
    println!("{}/{}", p, q);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


use std::io;
use std::str;

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn to_fraction(num: i64, denom: i64) -> (i64, i64) {
    let g = gcd(num, denom);
    (num / g, denom / g)
}

fn max_fraction(num1: i64, denom1: i64, num2: i64, denom2: i64) -> (i64, i64) {
    if num1 * denom2 < num2 * denom1 {
        to_fraction(num2, denom2)
    }
    else {
        to_fraction(num1, denom1)
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let a: i64 = scan.token();
    let b: i64 = scan.token();
    let c: i64 = scan.token();
    let d: i64 = scan.token();

    let num1 = a * d - b * c;
    let denom1 = a * d;
    let num2 = b * c - a * d;
    let denom2 = b * c;

    let ans = max_fraction(num1, denom1, num2, denom2);
    writeln!(out, "{}/{}", ans.0, ans.1).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}


fn main() {
    let mut sc = new(std::io::stdin());
    let n: usize = sc.next();
    let mut a: Vec<usize> = vec![];
    let mut tot = 0;
    for i in 0..n {
        a.push(sc.next());
        tot += a[i];
    }
    let mut dp = vec![vec![0;2]; n+1];
    for i in (0..n).rev() {
        if i == n - 1 {
            dp[i][0] = a[i];
            dp[i][1] = 0;
        } else {
            dp[i][0] = std::cmp::max(dp[i + 1][0], a[i] + dp[i + 1][1]);
            dp[i][1] = std::cmp::min(dp[i + 1][1] + a[i], dp[i + 1][0]);
        }
    }
    println!("{} {}", tot - dp[0][0], dp[0][0]);
}

use std::io;
use std::io::BufRead;

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

pub fn new<R: io::Read>(r: R) -> Scanner<R> {
    Scanner::new(r)
}

impl<R: io::Read> Scanner<R> {
    #[inline]
    fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: ")).unwrap()
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


use std::io;
use std::cmp;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: i32 = input.trim().parse().unwrap();
    let mut segs: Vec<(i32, i32, i32)> = vec![];
    for i in 0..(n+1) {
        for j in (i+1)..(n+1) {
            segs.push((j-i,i,j));
        }
    }
    segs.sort();
    let mut result: i32 = 0;
    let mut flags: Vec<bool> = vec![false; segs.len()];
    for i in (0..segs.len()).rev() {
        if flags[i] { continue; }
        let (size, mut a, mut b) = segs[i];
        flags[i] = true;
        let mut cur: i32 = size;
        while cur < n {
            let mut did_something = false;
            for j in (0..segs.len()).rev() {
                if flags[j] { continue; }
                let (s, c, d) = segs[j];
                if a == d || b == c {
                    if cur + s <= n {
                        a = cmp::min(a, c);
                        b = cmp::max(b, d);
                        cur += s;
                        flags[j] = true;
                        did_something = true;
                    }
                }
            }
            if !did_something { break; }
        }
        result += 1;
    }
    println!("{}", result);
}


fn main() {
    let areas: Vec<f64> = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();

    let a = (areas[0] * areas[1] / areas[2]).sqrt();
    let b = (areas[0] * areas[2] / areas[1]).sqrt();
    let c = (areas[2] * areas[1] / areas[0]).sqrt();
    let res = 4 * (a+b+c) as u32;

    println!("{}", res);

}

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer.trim().to_owned()
}

fn get_input_usize() -> usize {
    get_input().parse().unwrap()
}


fn read_string() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("Failed");
    input
}

fn main(){
    let now_time = read_string().replace("\n", "").replace("\r", "");
    let sleep_time = read_string().replace("\n", "").replace("\r", "");
    let now_vec: Vec<&str> = now_time.split(":").collect();
    let sleep_vec: Vec<&str> = sleep_time.split(":").collect();
    let mut hours = now_vec[0].parse::<i16>().unwrap() - sleep_vec[0].parse::<i16>().unwrap();
    let mut minutes = now_vec[1].parse::<i16>().unwrap() - sleep_vec[1].parse::<i16>().unwrap();
    if hours < 0{
        hours = 24+hours;
    }
    if minutes < 0{
        minutes = 60+minutes
    }
    println!("{}{}:{}{}", if hours<10 {"0"} else {""}, hours, if minutes<10 {"0"} else {""},minutes);
    }


use std::io::{self, Write};

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let n: usize = reads()[0];

    let mut aa: Vec<i32> = reads();

    while aa.len() > 0 {
        let mut maxi = 0;
        for i in 0..aa.len() {
            if aa[maxi] < aa[i] {
                maxi = i;
            }
        }

        if maxi > 0 && (aa[maxi - 1] - aa[maxi]).abs() >= 2 {
            println!("NO");
            return;
        }

        if maxi + 1 < aa.len() && (aa[maxi + 1] - aa[maxi]).abs() >= 2 {
            println!("NO");
            return;
        }

        aa.remove(maxi);
    }

    println!("YES");
}


use std::io::stdin;

fn main() {
    let mut buf = String::new();
    for _i in 0..3 {
        let _ = stdin().read_line(&mut buf);
        buf = buf.trim_end().to_string();
    }

    let x = buf.as_bytes();
    let mut ans = true;
    for i in 0..x.len()/ 2 {
        ans = ans && x[i] == x[x.len() - i - 1];
    }

    println!("{}", if ans { "YES" } else { "NO" });
}