Did Problem 2 in C# and Python