descr. and makefile for 5.
python solution (draft code)
C++ solution, based on rough python code. Times; python: ~1m1s C++: ~1.3s