make the function inline if u r using c++ and use getchar_unlocked() for more fast I/O
getchar_unlocked() is the thread unsafe version of getchar()The reason that getchar_unlocked() seems faster is that it doesn’t check for any locks on the input stream from where it is supposed to fetch a character. So if another thread has locked the input stream, this thread is supposed to wait till lock count has come to zero. But this function doesn’t care about it, thereby destroying synchronisation between threads.
But if you are sure that lack of synchronisation wont harm you, then this function might help you to be a bit faster.
inline int scan( )
while( ch <48 )ch=getchar_unlocked();
while( ch >47 )
n = (n<<3)+(n<<1) + ch-‘0’, ch=getchar_unlocked();