Title: おつり

Problem:
Taro often shops at the JOI variety store. The store has an ample supply of coins in denominations of 500 yen, 100 yen, 50 yen, 10 yen, 5 yen, and 1 yen. Taro always pays in a way that minimizes the number of coins he receives as change. Write a program to determine the number of coins Taro receives as change when he pays with a 1000 yen bill at the JOI store.

For example, for input 1, the output should be 4.

Input:
The input consists of multiple datasets. Each dataset consists of a single line containing the amount Taro pays (an integer between 1 and 999). The input ends with a single line containing 0.

There are no more than 5 datasets.

Output:
For each dataset, output the number of coins in the change received in a single line.

Input Example:
380
1
0

Output Example:
4
15

# Buggy version:
#!/usr/bin/env python
#coding:utf-8

coin = [500,100,50,10,5,1]
oturi = 1000 - int(input())
ret = 0
for c in coin:
    ret += oturi // c
    oturi %= c
print(ret)

# Fixed version:
#!/usr/bin/env python
#coding:utf-8

while True:
    coin = [500,100,50,10,5,1]
    oturi = 1000 - int(input())
    if oturi == 1000:
        break
    ret = 0
    for c in coin:
        ret += oturi // c
        oturi %= c
    print(ret)

# Buggy version:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

x = 1000 - int(input())

coins = [500, 100, 50, 10, 5, 1]

ret = 0
for coin in coins:
    n = x//coin
    x = x - n*coin
    ret += n

print(ret)

# Fixed version:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

coins = [500, 100, 50, 10, 5, 1]

while True:
    x = 1000 - int(input())
    if x == 1000:
        break

    ret = 0
    for coin in coins:
        n = x//coin
        x = x - n*coin
        ret += n

    print(ret)

# Buggy version:
c, o= 0, 1000-int(input())
def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

for l in [500, 100, 50, 10, 5, 1]: change(l)
print(int(c+o))

# Fixed version:
def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

while True:
    o= int(input())
    if o== 0: break
    c, o= 0, 1000-o
    for l in [500, 100, 50, 10, 5, 1]: change(l)
    print(c+o)

# Buggy version:
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
    p = int(input())
    ch = 1000 - p

    count = 0
    for coin in coins:
        n = ch // coin
        ch -= coin * n
        count += n
    
    print(count)

# Fixed version:
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
    while True:
        p = int(input())
        if p == 0:
            break
        ch = 1000 - p

        count = 0
        for coin in coins:
            n = ch // coin
            ch -= coin * n
            count += n
        
        print(count)

# Buggy version:
COINS = [500, 100, 50, 10, 5, 1]

change = 1000 - int(input())
total = 0
for coin in COINS:
    total += change // coin
    change %= coin

print(total)

# Fixed version:
COINS = [500, 100, 50, 10, 5, 1]

change = 1000 - int(input())
while change != 1000:
    total = 0
    for coin in COINS:
        total += change // coin
        change %= coin

    print(total)

    change = 1000 - int(input())

# Buggy version:
for e in iter(input,'0'):
while 1:
 b,c=1000-int(e),0
 for i in[500,100,50,10,5]:
  d,b=divmod(b,i)
  c+=d
 print(b+c)


# Fixed version:
for e in iter(input,'0'):
 b,c=1000-int(e),0
 for i in[500,100,50,10,5]:
  d,b=divmod(b,i)
  c+=d
 print(b+c)

# Buggy version:
for e in iter(input,'0'):
 a,b=0,1000-int(e)
 for i in[500,100,50,10,5]:
  b%=i
  a+=b//i
 print(b+a)


# Fixed version:
for e in iter(input,'0'):
	a,b=0,1000-int(e)
	for i in[500,100,50,10,5]:
		a+=b//i
		b%=i
	print(a+b)