Codeforces Round #108 Problem C Pocket Book