KGP16D solution help

Hi can anyone provide hints to solve this problem KGP16D ? I am wondering if there is a solution without any ad-hoc or pattern approach.