fixed time limit exceeded on 1021
fixed a few time limits, learned the basics of dynamic programming