Storing the sum beforehand so that it can be used in each query
sums = [ 0 ] * kN ; NEW_LINE sums [ 0 ] = 0 ; NEW_LINE for i in range ( 1 , kN ) : NEW_LINE INDENT sums [ i ] = ( i * i ) + sums [ i - 1 ] ; NEW_LINE DEDENT