Solution Problem A: Collecting Beats is Fun
Codeforces Round #219