The exact solution may be hard to reproduce due to some messy experiment code (we all do it sometimes during the comps), but I tried to preserve the main idea and clean the code as much as possible.