Solving codechef medium level