Correct solution to ICPC Problem 3871. Attempt at solution for ICPC Problem 3869.