First attempt at a naive solution
Remove range-based for-statement
Whoops\!
This O(n^2) solution is accepted by the [practice] contest judge )-:
Initial attempt, nothing special
initial attempt
Submissions from the live contest