The problem description says "Each Yi type will not appear more than once". But according to my asserts, they do occur several times. So, it is not clear what to do in such a case.