Minimal number of banknotes to pay a bill Suppose denominations of banknotes follow the infinity Hyperinflation sequence: \$ $1, $2, $5, $10, $20, $50, $100, $200, $500, $1000, $2000, $5000, \cdots \$. How many banknotes are required, at minimum, to pay a \$$n\$ bill?
Consider Alice needs to pay \$ $992 \$ to Bob. It is possible for Alice to use 7 banknotes \$ $500, $200, $200, $50, $20, $20, $2 \$ to pay the bill, but that uses a lot of banknotes. We can see that a better solution is: Alice pays 2 banknotes (\$ $1000, $2 \$), and Bob gives her \$ $10 \$ in change. So, we only need 3 banknotes here.
Formal Definition
Banknotes follow an infinite sequence \$b_i\$:
$$ b_n=10\cdot b_{n-3} $$
with base cases
$$ b_1=1, b_2=2, b_3=5 $$
When Alice pays \$ $x \$ to Bob, Alice pays \$ a_i \$ banknotes with denominations \$b_i\$. \$ a_i \in \mathbb{Z} \$ And
$$ \sum a_ib_i=x $$
\$ a_i \$ may be negative which means Bob gives Alice these banknotes in change.
You are going to calculate:
$$ f\left(x\right)=\min_{\sum a_ib_i=x} \sum\left|a_i\right| $$
Input / Output
Input a non-negative number representing the amount of money to pay. Output the minimum number of banknotes required.
Rules

This is code-golf: Shortest codes in bytes win.
Your program should be able to handle inputs \$ 0 \le n &lt; 100{,}000 \$ at least. Your algorithm should work for arbitrary large numbers in theory.
As this questions is only focused on integers, floating point errors are not allowed.

Testcases
Input -&gt; Output
    0 -&gt; 0
    1 -&gt; 1
    2 -&gt; 1
    3 -&gt; 2
    4 -&gt; 2
    5 -&gt; 1
    6 -&gt; 2
    7 -&gt; 2
    8 -&gt; 2
    9 -&gt; 2
   10 -&gt; 1
   11 -&gt; 2
   12 -&gt; 2
   13 -&gt; 3
   14 -&gt; 3
   15 -&gt; 2
   16 -&gt; 3
   17 -&gt; 3
   18 -&gt; 2
   19 -&gt; 2
   20 -&gt; 1
   40 -&gt; 2
   41 -&gt; 3
   42 -&gt; 3
   43 -&gt; 3
   44 -&gt; 3
   45 -&gt; 2
   46 -&gt; 3
   47 -&gt; 3
   48 -&gt; 2
   49 -&gt; 2
   50 -&gt; 1
   90 -&gt; 2
   91 -&gt; 3
   92 -&gt; 3
   93 -&gt; 3
   94 -&gt; 3
   95 -&gt; 2
   96 -&gt; 3
   97 -&gt; 3
   98 -&gt; 2
   99 -&gt; 2
  100 -&gt; 1
  980 -&gt; 2
  981 -&gt; 3
  982 -&gt; 3
  983 -&gt; 4
  984 -&gt; 4
  985 -&gt; 3
  986 -&gt; 4
  987 -&gt; 4
  988 -&gt; 3
  989 -&gt; 3
  990 -&gt; 2
  991 -&gt; 3
  992 -&gt; 3
  993 -&gt; 3
  994 -&gt; 3
  995 -&gt; 2
  996 -&gt; 3
  997 -&gt; 3
  998 -&gt; 2
  999 -&gt; 2
 1000 -&gt; 1
 1341 -&gt; 6
 2531 -&gt; 5
 3301 -&gt; 5
 4624 -&gt; 6
 5207 -&gt; 4
 6389 -&gt; 6
 6628 -&gt; 7
 6933 -&gt; 6
 7625 -&gt; 6
 8899 -&gt; 4
13307 -&gt; 7
23790 -&gt; 5
33160 -&gt; 7
33325 -&gt; 8
40799 -&gt; 5
55641 -&gt; 7
66472 -&gt; 8
77825 -&gt; 6
89869 -&gt; 6
98023 -&gt; 5
Python 2, 87 80 68 bytes

f=lambda x:x&gt;1and min((y%10)**6%305%3+f(y/10*x/y)for y in[x,-x])or x

Try it online!
-7 bytes thanks to @tsh, and -12 bytes thanks to @dingledooper. Thanks to everyone else for their own golf suggestions.
Instead of tearing down the banknotes in the top-down way, this solution builds up the answer from the bottom. Since the number of banknotes needed to pay \$10n\$ is exactly the same as that for \$n\$, we can tear down the banknotes from the one's digit in the following sense:

If the one's digit is 0, remove the 0 and recurse.

Otherwise, consider two ways to fulfill the one's digit:

Alice pays n%10 to Bob, and then Alice pays whatever banknotes are needed to pay floor(n/10) * 10. Recurse with floor(n/10).
Bob pays 10-n%10 to Alice, and then Alice pays whatever banknotes are needed to pay ceil(n/10) * 10. Recurse with ceil(n/10).

Then we can evaluate the two cases and take their minimum.


In the code, an infinite recursion happens if we don't special-case x=1 as well as x=0, because the ceiling of 1/10 is still 1.