Add solution for codeforces round 249 problem C "Cardiogram"