http://codeforces.com/contest/347/problems A
http://codeforces.com/contest/347/problems B