algorithm pre_and_core