Set ds=∣as−bs∣, 0≤s≤9, where b0=0. Without loss of generality assume that there exists k, 0≤k≤8 such that as−bs>0 for 0≤s≤k and as−bs<0 for k+1≤s≤9.
If n is one of the desired values then there exist positive integers x0,x1,…,x9 for which
(⋆)x0d0+⋯+xkdk−xk+1dk+1−⋯−x9d9=n.
Therefore d=GCD(d0,d1,…,d9) is a divisor of n.
We prove now that if d is a divisor of n then one can empty the cash machine.
Indeed, in this case it follows from Bezout's theorem that (⋆) has solution (x0,x1,…,x9) in integers. Set D1=d0+⋯+dk, D2=dk+1+⋯+d9, xs′=xs+tD2, 0≤s≤k, xs′=xs+tD1, k+1≤s≤9. Since D1,D2>0, it is clear that for big enough t, (x0′,…,x9′) is a solution of (⋆) in positive integers and x9′>max(a8,…,ak+1). Consider one such solution and let x0′′=x0′+rD2, xs′′=xs′, 1≤s≤k and xs′′=xs′+rd0, k+1≤s≤9. For big enough r we obtain a solution (x0′′,…,x9′′) of (⋆), for which
(⋆⋆)x9′′≥max(a8,…,ak+1)
(⋆⋆⋆)n+x9′′d9+⋯+xk+1′′dk+1>x1′′d1+⋯+xk′′dk.
We draw money in the following way. Take first x9′′ times a9 leva then x8′′ times a8 leva, ..., xk+1′′ times ak+1 leva. After that we take x1′′ times a1 leva, ..., xk′′ times ak leva. Since (⋆⋆) and (⋆⋆⋆) all operations are feasible. Now (⋆) implies that there are exactly x0′′d0 leva left in the machine and we withdraw them by taking x0′′ times a0 leva.
Answer. All n≥a9 divisible by d.