Problem 3 in C# and Python