sum in sorted sequence