Add the sum of squares of stack elements not equal to 1
while ( S > 0 ) : NEW_LINE INDENT c += 1 NEW_LINE if ( S // 8 > 0 ) : NEW_LINE INDENT res += 9 * 9 NEW_LINE S -= 8 NEW_LINE DEDENT else : NEW_LINE INDENT res += ( S + 1 ) * ( S + 1 ) NEW_LINE break NEW_LINE DEDENT DEDENT