P9, P25, P26, P27, P28, P31, P32, P39, P40, P47, P48, P49, P50, P58, P59, P60, P69, P70, P74, P79: Simplified and tweaked Java solution for clarity.