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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 
import java.util.*;

class Main{ 

	static void solve(){
		int n = ni();
		long[] s = nla(n);
		boolean[] isPrime = new boolean[100001];
		Arrays.fill(isPrime, true);
		for(int i=2;i<=100000;++i){
			if(!isPrime[i])continue;
			for(int j=i*2;j<=100000;j+=i)isPrime[j]=false;
		}
		List<Integer> primes = new ArrayList<>();
		for(int i=2;i<=100000;++i)if(isPrime[i])primes.add(i);
		Set<Long> under1e5 = new HashSet<>();
		for(int p: primes)under1e5.add((long)p);
		under1e5.add(1L);
		List<Long> cubep = new ArrayList<>();
		for(int p : primes){
			if((long)p*p*p>(long)1e10)break;
			cubep.add((long)p);
		}

		Map<Long, Long> reve = new HashMap<>();
		Map<Long , Integer> cnt = new HashMap<>();
		int ans = 0;
		boolean zero=true;
		for(int i=0;i<n;++i){
			long ss = s[i];
			long rev = 1;
			for(int k=0;k<cubep.size();++k){
				long p= cubep.get(k);
				while(s[i]%(p*p*p)==0)s[i]/=(p*p*p);
				if(s[i]%p==0){
					if(s[i]%(p*p)==0)rev*=p;
					else rev*=p*p;
				}
				while(s[i]%p==0)s[i]/=p;
			}
			if(!under1e5.contains(s[i])){
				++ans;continue;
			}
			if((int)Math.sqrt(s[i])*(int)Math.sqrt(s[i])==s[i])rev*=s[i];
			else rev*=(s[i]*s[i]);
//			out.println(s[i]+" "+rev);
			if(rev==1){
				if(zero)++ans;
				zero=false;continue;
			}
			reve.put(ss, rev);
			cnt.put(ss, cnt.getOrDefault(ss, 0)+1);
		}

		int ans2 = 0;
		Set<Long> used = new HashSet<>();
		for(Map.Entry<Long , Integer> entry: cnt.entrySet()){
			if(used.contains(entry.getKey()))continue;
			ans2 += Math.max(entry.getValue(), cnt.getOrDefault(reve.get(entry.getKey()), 0));
			used.add(reve.get(entry.getKey()));
		}
//		out.println(ans+" "+ans2);
		out.println(ans+ans2);
	}
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
}