Template code of algorithm.