In the problem statement, it said "There is a blank line before every case." But in the sample, there is no space before the first case? Which one should I follow. In addition, I tried submitting in both ways, but I am getting WA.
@brianfry713: Thanks. I used scanf to avoid the blank line problem.
@mubashwir: Thanks vaia. After seeing your test cases I realized the statement asked for "number of different static states that can be reached from the original position by enabling at least one gravity". Initially the gravity is off. So sometimes the initial state given may not be static. I simply removed two lines and got AC