Algorithms task solving using python