Solution for code contest