using
System;
using
System.Collections.Generic;
class
GFG
{
static
List<
int
> getPerfectcubes(
int
n) {
List<
int
> perfectcubes =
new
List<
int
>();
int
current = 1;
int
i = 1;
while
(current <= n) {
perfectcubes.Add(current);
i += 1;
current = (
int
) (Math.Pow(i, 3));
}
return
perfectcubes;
}
static
int
maxPairSum(
int
[] arr) {
int
n = arr.Length;
int
max = 0;
int
secondMax = 0;
if
(arr[0] > arr[1]) {
max = arr[0];
secondMax = arr[1];
}
else
{
max = arr[1];
secondMax = arr[0];
}
for
(
int
i = 2; i < n; i++) {
if
(arr[i] > max) {
secondMax = max;
max = arr[i];
}
else
if
(arr[i] > secondMax) {
secondMax = arr[i];
}
}
return
(max + secondMax);
}
static
int
countPairsWith(
int
n, List<
int
>
perfectcubes, List<
int
> nums) {
int
count = 0;
for
(
int
i = 0; i < perfectcubes.Count; i++) {
int
temp = perfectcubes[i] - n;
if
(temp > n && (nums.Contains(temp)))
count += 1;
}
return
count;
}
static
int
countPairs(
int
[] arr) {
int
n = arr.Length;
int
max = maxPairSum(arr);
List<
int
> perfectcubes = getPerfectcubes(max);
List<
int
> nums =
new
List<
int
>();
for
(
int
i = 0; i < n; i++) {
nums.Add(arr[i]);
}
int
count = 0;
for
(
int
i = 0; i < n; i++) {
count += countPairsWith(arr[i], perfectcubes, nums);
}
return
count;
}
public
static
void
Main(String[] agrs) {
int
[] arr = { 2, 6, 18, 9, 999, 1 };
Console.Write(countPairs(arr));
}
}