Problem 5: only Python (could not implement in C); problem 6: C