P249, P271, P301, P357: Tweaked Java solution.
P117: Tweaked Haskell solution.