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: Wrong Answer)

// 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);
                total += max(ac, mac);
            }
        } else {
            total += max(ac, bc);
        }
    }
    total
}


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

    let (p, _) = generate_primes(100000);
    let pn = p.len();
    let mut low_primes = vec![];
    let mut high_primes = vec![];
    for i in 0..pn {
        if p[i] < 2155 {
            low_primes.push(p[i]);
        } else {
            high_primes.push(p[i]);
        }
    }

    let ln = low_primes.len();
    let hn = high_primes.len();

    let mut nlist = vec![];
    for i in 0..n {
        let mut w = a[i];
        let mut norm = 1;
        let mut cnorm = 1;
        for j in 0..ln {
            let mut ct = 0;
            while w >= low_primes[j] && w % low_primes[j] == 0 {
                w /= low_primes[j];
                ct += 1;
            }
            ct %= 3;
            for c in 0..ct {
                norm *= low_primes[j];
            }
            for c in 0..((3-ct)%3) {
                cnorm *= low_primes[j];
            }
        }
        nlist.push((norm, cnorm, w));
    }
    nlist.sort();

    let mut wmap = HashMap::<i64, Vec<usize>>::new();
    for i in 0..n {
        if wmap.contains_key(&nlist[i].2) {
            wmap.get_mut(&nlist[i].2).unwrap().push(i);
        } else {
            wmap.insert(nlist[i].2, vec![]);
        }
    }
    let mut visited = vec![false; n];
    for h in 0..hn {
        let hi = h as i64;
        let p0 = high_primes[h];
        let p1 = high_primes[h]*high_primes[h];
        for &idx in wmap.get(&p0).unwrap_or(&vec![]) {
            visited[idx] = true;
            nlist[idx].2 = 1000+hi;
        }
        for &idx in wmap.get(&p1).unwrap_or(&vec![]) {
            visited[idx] = true;
            nlist[idx].2 = -(1000+hi);
        }
    }
    for i in 0..n {
        if !visited[i] {
            if nlist[i].2 != 1 {
                nlist[i].2 = 1;
            } else {
                nlist[i].2 = 0;
            }
        }
    }

    let mut id_map = HashMap::new();
    let mut groups = vec![];
    {
        let mut i = 0;
        while i < n {
            let mut w = vec![];
            let mut j = i;
            while j < n && nlist[i].0 == nlist[j].0 {
                w.push(nlist[j].2);
                j += 1;
            }
            id_map.insert(nlist[i].0, groups.len());
            groups.push((nlist[i].0, nlist[i].1, w));
            i = j;
        }
    }

    // debug!(groups);

    let mut ans = 0;
    let gn = groups.len();
    for i in 0..gn {
        if let Some(&j) = id_map.get(&groups[i].1) {
            if i < j {
                ans += solve(groups[i].2.clone(), groups[j].2.clone(), false);
            } else if i == j {
                ans += solve(groups[i].2.clone(), vec![], false);
            }
        } else {
            ans += solve(groups[i].2.clone(), vec![], false);
        }
    }
    println!("{}", ans);
}