spoj0; solve "Grading" from Contest 67