I am also having trouble with this problem. Is the inputs and output really won't exceed 2^31?
I thought that maybe the intermediate results can be larger than 2^31 or maybe even much more...so I used BigInt anyway, but got runtime error!!
Can somebody post some sample input? I need to know how likely the inputs could be, thanks.
