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:
9.4m questions
12.2m answers