OUCH!
long long ans = LONG_MAX, instead of LLONG_MAX, and that was my submission to problem C GONE.
Codeforces Round 1096 Solution Discussion