I hope you don't find the solution too messy. If there is anything you don't get. Let me know and I will explain it:
6.5m questions
8.6m answers