how to solve the first problem ??
check this thread for all questions :- https://codeforces.com/blog/entry/83100