One lesson I have learned on last Div #3 contest is "avoid using pow() function in C++, it is can lead to Wrong Answer".
I am sharing this with a practical example:
This submission works only if you replace long long p = pow(n1, 3) + pow(mid, 3);
with long long p = n1 * n1 * n1 + mid * mid * mid;
I feel like it is useful to sare it !