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)

use std::io;
use std::collections::BTreeSet;
use std::collections::BTreeMap;
use std::cmp;

const MAX: usize = 10000000000;

fn main() {
    let primes = get_primes(100000);
    let p2 = primes.iter().map(|p| p * p).collect::<BTreeSet<_>>();
    let mut pair_map = BTreeMap::new();
    let mut count_map = BTreeMap::new();

    let n = read_values::<usize>()[0];
    for _ in 0..n {
        let mut s = read_values::<usize>()[0];
        let mut normal = 1;
        let mut pair = 1;
        for prime in primes.iter() {
            let prime = *prime;
            let p3 = prime * prime * prime;
            if p3 > MAX {
                break;
            }
            while s % p3 == 0 {
                s /= p3;
            }
            if s % (prime * prime) == 0 {
                s /= (prime * prime);
                pair *= prime;
                normal *= (prime * prime);
            } else if s % prime == 0 {
                s /= prime;
                normal *= prime;
                pair *= (prime * prime);
            }
            if pair > MAX {
                pair = 0;
            }
        }
        if s != 1 {
            if p2.contains(&s) {
                let p = (s as f64).sqrt() as usize;
                normal *= s;
                pair *= p;
            } else {
                normal *= s;
                pair *= s;
                if pair > MAX || (pair > 100000 && s > 100000) {
                    pair = 0;
                }
                pair *= s;
            }
        }

        if count_map.contains_key(&normal) {
            let cur = *count_map.get(&normal).unwrap();
            count_map.insert(normal, cur + 1);
        } else {
            count_map.insert(normal, 1);
        }
        pair_map.insert(normal, pair);
    }

    let mut ans = 0;
    let mut checked = BTreeSet::new();
    match count_map.get(&1) {
        Some(_) => {
            ans += 1;
            checked.insert(1);
        }
        _ => {}
    }
    for item in pair_map.iter() {
        let (normal, pair) = item;
        let normal_count = *count_map.get(normal).unwrap();
        let pair_count = match count_map.get(pair) {
            Some(count) => *count,
            _ => 0,
        };
        if checked.contains(normal) {
            continue;
        }
        ans += cmp::max(normal_count, pair_count);
        checked.insert(*normal);
        checked.insert(*pair);
    }
    println!("{}", ans);
}

fn get_primes(n: usize) -> Vec<usize> {
    let mut is_prime = vec![true; n + 1];
    is_prime[0] = false;
    is_prime[1] = false;

    for p in 2..(n + 1) {
        if is_prime[p] {
            let mut c = 2;
            while c * p <= n {
                is_prime[c * p] = false;
                c += 1;
            }
        }
    }

    let mut primes = Vec::new();
    for i in 2..(n + 1) {
        if is_prime[i] {
            primes.push(i);
        }
    }
    primes
}

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

fn read_values<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}