Assignment:
Solution by compartiment.
Answer:
Provide input first