Interlos 2016 - P2 Naive bruteforce algorithm (but it solves the problem so..). Results in ~2 seconds.
Problem https://interlos.fi.muni.cz/download/years/2016/sada1/
Official solution https://interlos.fi.muni.cz/download/years/2016/reseni/reseni.pdf