Here is the link to the problem https://www.spoj.com/problems/NASIO/. I can’t find any pattern or formula. Please help me.