implement problem, need some kind of hash to save space, also use C I/O to save time, refer others' algo