First commit of codes for problems 3 and last parts of problem 1