recursive sum and max function