Can anybody help me reduce the processing time of my code? (LAYERS)

https://www.codechef.com/viewsolution/28563884