Bad neighbors topcoder problem