solve by BF, slow, is there a better way ?