Question: Let's consider the following sequence:

$$9,8,7,6,5,4,3,2,1,0,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71...$$
This is the sequence of \$9\$'s complement of a number: that is, \$ a(x) = 10^d - 1 - x \$ where \$ d \$ is the number of digits in \$ x \$. ([A061601](https://oeis.org/A061601) in the OEIS).Your task is to add the first \$n\$ elements.

### Input

A number \$n∈[0,10000]\$.

### Output

The sum of the first \$n\$ elements of the sequence.

### Test cases

```
0 -> 0
1 -> 9
10 -> 45
100 -> 4050
1000 -> 408600
10000 -> 40904100

```

Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. The shortest code in bytes wins.

Answer: 
[Zsh](https://www.zsh.org/), 35 bytes
=====================================

```
for ((x=$1;x--;s+=1e$#x+~x)):
<<<$s
```

[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhY3ldPyixQ0NCpsVQytK3R1rYu1bQ1TVZQrtOsqNDWtuGxsbFSKIUqhOpZGGxoYxEI5AA)
[Desmos](https://desmos.com/calculator), 49 bytes
=================================================

```
f(k)=∑_{n=2}^k(10^{1+floor(log(n-1))}-n)+9-0^k9

```

Would be 44 bytes if we didn't have to deal with 0...

[Try It On Desmos!](https://www.desmos.com/calculator/hx3t6kc5n5)

[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/hogm4nge2i)

48 bytes, port of [@tsh](https://codegolf.stackexchange.com/users/44718/tsh)'s [answer](https://codegolf.stackexchange.com/a/243275/96039)
------------------------------------------------------------------------------------------------------------------------------------------

```
t=10^{log(n+0^n)}10
f(n)=tn-(nn+n)/2-(tt-100)/11

```

[Try It On Desmos!](https://www.desmos.com/calculator/epcgwgznbc)