optimizing sum