Let's work on $v_p(a_i)=t(i)_p$ for any $p|a_t$ for some $t$
Define $C=\left\{ (i;j)|\leq 1i<j\leq n,a_ia_j=c^3\right\}$
Case 1: Exist $t(i)_p \vdots 3$ for some $i,p$
Then if products of $a_i$ with some $a_t$ is a cube then $t(j)_p \vdots 3$ and $\frac{a_ia_j}{p^{t(i)_p+t(j)_p}}$ is a cube
So we can assume there is no $t(i)_p \vdots 3$
So
So now let's do with case 2:
Case 2: There is no $t(i)_p \vdots 3$ for some $i,p$
Works: For any $p$, define $A_j=\left\{ i||t(i)_p\equiv j \, \, (mod\, \, 3)\right\}$
Then $|C| \leq |A_1||A_2| \leq \frac{(|A_1|+|A_2|)^{2}}{4}\leq \frac{n^2}{4}$
Equality happen when there is $n/2$ $a_i$ is 3k+1-th power of a prime, and the others is 3k+2-th power of that prime