Week 5. Problems 1-3

Problems 1, 2 changed. Need verify correctness.