solution of Facebook Hacker Cup 2013 Quali problem