Solution for problem 1
Solution for problem 2
Solution for problem 3
Solution for problem 4