Wow, nice davido. However, all of those still gave 'time limit exceeded'. Actually, all of the responses here did. Though they were all far better than my attempt! Here is the link explaining this message from the site:
http://www.codechef.com/wiki/faq#Why_do_I_get_a_Time_Limit_Exceeded