code finished for 277 div2 c