When N >= len then more squares will be counted
if ( N >= len ) : NEW_LINE INDENT N -= len NEW_LINE for i in range ( 1 , len ) : NEW_LINE INDENT ans += i NEW_LINE DEDENT DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT ans += i NEW_LINE DEDENT