solved problemB codecup 2014 r1