how to solve addition question

http://www.codechef.com/CODS2013/problems/COADIES4 how to solve such kind of questions

//