When I submit my code here for Problem C to Codeforces Round 291, it gives me runtime error although I've tried my code both on my local compiler and on ideone.com, both of which give me correct outputs. Why is this happening? Any help would be appreciated.