619 solution in ugly java