public class BearDartsDiv2 {
public long count(int[] w) {
final int LIM = 1000 * 1000;
int[] m = new int[LIM + 1];
int n = w.length;
long result = 0;
for(int d = 0; d < n; ++d) {
result += m[w[d]];
for(int a = 0; a < d; ++a)
for(int b = a + 1; b < d; ++b) {
long mul = (long) w[a] * w[b] * w[d];
if(mul <= LIM) m[(int) mul]++;
}
}
return result;
}
}
cHVibGljIGNsYXNzIEJlYXJEYXJ0c0RpdjIgewogICAgcHVibGljIGxvbmcgY291bnQoaW50W10gdykgewogICAgICAgIGZpbmFsIGludCBMSU0gPSAxMDAwICogMTAwMDsKICAgICAgICBpbnRbXSBtID0gbmV3IGludFtMSU0gKyAxXTsKICAgICAgICBpbnQgbiA9IHcubGVuZ3RoOwogICAgICAgIGxvbmcgcmVzdWx0ID0gMDsKICAgICAgICBmb3IoaW50IGQgPSAwOyBkIDwgbjsgKytkKSB7CiAgICAgICAgICAgIHJlc3VsdCArPSBtW3dbZF1dOwogICAgICAgICAgICBmb3IoaW50IGEgPSAwOyBhIDwgZDsgKythKQogICAgICAgICAgICAgICAgZm9yKGludCBiID0gYSArIDE7IGIgPCBkOyArK2IpIHsKICAgICAgICAgICAgICAgICAgICBsb25nIG11bCA9IChsb25nKSB3W2FdICogd1tiXSAqIHdbZF07CiAgICAgICAgICAgICAgICAgICAgaWYobXVsIDw9IExJTSkgbVsoaW50KSBtdWxdKys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICB9Cn0=