Disclaimers:
- As the inputs are well-formatted, I enjoy to employ code golf to spend minimum effort to parse it. Readability of parsing logic is not a priority here (normally it would be!)
- While at it, I also enjoy code golf for the solutions... Bad me!
- Functional programming FTW. No mutability.