If it 's size is less than k  it needed to be increased
while ( len ( val [ cur ] ) < k and len ( extra ) > 0 ) : NEW_LINE INDENT elem = extra [ - 1 ] [ 0 ] NEW_LINE mmod = extra [ - 1 ] [ 1 ] NEW_LINE extra . pop ( ) NEW_LINE val [ cur ] . append ( elem ) NEW_LINE ans += i - mmod NEW_LINE DEDENT return ans NEW_LINE