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)

// https://atcoder.jp/contests/agc003/tasks/agc003_d
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

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

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

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

#[allow(unused_macros)]
macro_rules! read_line {
    ($t:tt) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().parse::<$t>().unwrap()
        }
    }
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

fn generate_primes(upto: usize) -> (Vec<i64>, Vec<bool>) {
    let mut is_prime = vec![true; upto+1];
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..upto+1 {
        if is_prime[i] {
            let mut ii = i * i;
            while ii <= upto {
                is_prime[ii] = false;
                ii += i;
            }
        }
    }

    let mut primes = vec![];
    for i in 0..upto+1 {
        if is_prime[i] {
            primes.push(i as i64);
        }
    }
    (primes, is_prime)
}

const LIMIT: i64 = 1e10 as i64;

fn solve(a: Vec<i64>, b: Vec<i64>, one: bool) -> i64 {
    let mut totalmap = HashMap::new();
    let mut amap = HashMap::new();
    let mut flag = 1;
    for list in vec![&a, &b] {
        for &a in list {
            let key = flag*a;
            if let Some(&w) = totalmap.get(&key) {
                totalmap.insert(key, w+1);
            } else {
                totalmap.insert(key, 1i64);
            }
        }
        flag *= -1;
    }
    for &a in &a {
        if let Some(&w) = amap.get(&a) {
            amap.insert(a, w+1);
        } else {
            amap.insert(a, 1i64);
        }
    }

    let mut total = 0;
    for (key, count) in totalmap {
        let ac = *amap.get(&key).unwrap_or(&0);
        let bc = count-ac;
        if one {
            if key < 0 {
                continue;
            }
            if key == 0 {
                total += 1;
            } else {
                let mac = *amap.get(&-key).unwrap_or(&0);
                // debug!(key, ac, mac);
                total += max(ac, mac);
            }
        } else {
            total += max(ac, bc);
        }
    }
    total
}


fn main() {
    input! {
        n: usize,
        a: [i64; n]
    };

    let (p, _) = generate_primes(1000000);
    let pn = p.len();

    let low_primes = p.clone().into_iter().filter(|&x| x < 2200).collect::<Vec<_>>();

    let mut p3map_all = HashMap::<i64, i64>::new();
    for i in 1..2500 {
        p3map_all.insert(i*i*i, i);
    }

    let mut p3map = HashMap::<i64, i64>::new();
    let mut p2map = HashMap::<i64, i64>::new();
    let mut p1map = HashMap::<i64, i64>::new();
    for i in 0..pn {
        p3map.insert(p[i]*p[i]*p[i], p[i]);
        p2map.insert(p[i]*p[i], p[i]);
        p1map.insert(p[i], p[i]);
    }


    // 2155
    let mut singular = 0;
    let mut map = HashMap::<(i64, i64), i64>::new();
    let mut ans = 0;
    let mut has_p3 = false;
    for i in 0..n {
        if p3map_all.contains_key(&a[i]) {
            has_p3 = true;
            continue;
        }
        let mut aa = a[i];
        let mut base = 1;
        let mut antibase = 1;
        for &p in &low_primes {
            let mut count = 0;
            while aa % p == 0 {
                aa /= p;
                count += 1;
            }
            count %= 3;
            base *= p.pow(count);
            antibase *= p.pow((3-count)%3);
        }
        if aa >= 2 {
            if let Some(&p) = p1map.get(&aa) {
                base *= p;
                antibase *= p*p;
            } else if let Some(&p) = p2map.get(&aa) {
                base *= p*p;
                antibase *= p;
            } else {
                singular += 1;
                continue;
            }
        }

        assert!(base != 1);
        if let Some(&mut x) = map.get_mut(&(base, antibase)) {
            map.insert((base, antibase), x+1);
        } else {
            map.insert((base, antibase), 1);
        }
    }

    let mut half = 0;
    for (&(k0, k1), &v) in &map {
        if let Some(&u) = map.get(&(k1, k0)) {
            ans += max(v, u);
        } else {
            half += v;
        }
    }
    ans /= 2;
    ans += half;
    ans += singular;
    ans += ifv!(has_p3, 1, 0);
    println!("{}", ans);
}