uva 10646, 12247, 555 solutions