How to take input

https://hack.codingblocks.com/contests/c/916/58

I am unable to set the condition so that I can limit my input buffer
it is difficult to set the range of inputs. Please help me to resolve this.