ex5 solved without optional exercises