How to solve this problem in less time?

I am getting Time limit exceeded in this problem. how can i solve it?

hey Deepanshu, please save your code in https://ide.codingblocks.com/ and share the link here.