Solution by Kian-Meng Ang
