Problem:
Score : 1100 points

Problem Statement

Snuke got positive integers s_1,...,s_N from his mother, as a birthday present. There may be duplicate elements.

He will circle some of these N integers. Since he dislikes cubic numbers, he wants to ensure that if both s_i and s_j (i ≠ j) are circled, the product s_is_j is not cubic. For example, when s_1=1,s_2=1,s_3=2,s_4=4, it is not possible to circle both s_1 and s_2 at the same time. It is not possible to circle both s_3 and s_4 at the same time, either.

Find the maximum number of integers that Snuke can circle.

Constraints

1 ≦ N ≦ 10^5

1 ≦ s_i ≦ 10^{10}

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
s_1
:
s_N

Output

Print the maximum number of integers that Snuke can circle.

Sample Input 1

8
1
2
3
4
5
6
7
8

Sample Output 1

6

Snuke can circle 1,2,3,5,6,7.

Sample Input 2

6
2
4
8
16
32
64

Sample Output 2

3

Sample Input 3

10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999

Sample Output 3

9

Solution in Rust (1.15.1) (judge verdict: Accepted)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let ps = primes(100000);
    let ps1: HashSet<usize> = ps.iter().cloned().skip_while(|&x| x * x * x < 10000000000).collect();
    let ps2: HashMap<usize, usize> = ps1.iter().map(|&x| (x * x, x)).collect();
    let mut ans = 0;
    let mut map: HashMap<usize, (Vec<(usize, usize)>, usize, usize)> = HashMap::new();
    let mut ans1 = 0;
    for &s in &v {
        let mut a = s;
        let mut b = s;
        let mut fac = vec![];
        for &p in &ps {
            if p * p * p > 10000000000 {
                break;
            }
            let mut r = 0;
            while a % p == 0 {
                a /= p;
                r += 1;
            }
            b /= p.pow(r as u32 / 3 * 3);
            if r % 3 != 0 {
                fac.push((p, r % 3));
            }
        }
        if b == 1 {
            ans1 = 1;
            continue;
        }
        if let Some(e) = map.get_mut(&b) {
            e.2 += 1;
            continue;
        }
        map.insert(b, (fac, a, 1));
    }
    for val in map.values() {
        let mut a2 = val.0.iter().fold(1, |ac, &(p, r)| ac * p.pow(3 - r as u32));
        if ps1.contains(&val.1) {
            a2 *= val.1 * val.1;
        } else if ps2.contains_key(&val.1) {
            a2 *= *ps2.get(&val.1).unwrap();
        } else if val.1 > 1 {
            ans1 += val.2;
            continue;
        }
        if let Some(&(_, _, c)) = map.get(&a2) {
            ans += max(val.2, c);
        } else {
            ans1 += val.2;
        }
    }
    ans = ans / 2 + ans1;
    println!("{}", ans);
}

fn primes(n: usize) -> Vec<usize> {
    if n < 2 {
        return vec![];
    }
    let mut tab = vec![true; n + 1];
    let mut ps = vec![2];
    for i in 2..n / 2 + 1 {
        tab[i * 2] = false;
    }
    let mut p = 3;
    while p * p <= n {
        if tab[p] {
            ps.push(p);
            for i in 2..n / p + 1 {
                tab[i * p] = false;
            }
        }
        p += 2;
    }
    while p <= n {
        if tab[p] {
            ps.push(p);
        }
        p += 2;
    }
    ps
}