Partial sum problem (P.34)