Help with [QUCO2014] Bored in Class.

My code works fine with the test cases I used, but I got a WA. Can someone tell me what’s wrong with it? Are there any extreme cases that I am missing?

http://ideone.com/e.js/FQKGtb