algorithm implementation for ICPC team note