Solution of first problem in Python.