Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

Python: i=0
while i<6:
    i+=1
    x=int(input())
    y=1000-x
    g=y//500
    h=(y-500*g)//100
    d=(y-500*g-100*h)//50
    z=(y-500*g-100*h-50*d)//10
    f=(y-500*g-100*h-50*d-10*z)//5
    i=y-500*g-100*h-50*d-10*z-5*f
    if x==0:
        break
    print(g+h+d+z+f+i)

Python: while True:
    n=int(input())
    if n==0:
        break
    m=1000-n
    a=0
    for i in [500,100,50,10,5,1]:
        a+=m//i
        m=m%i
    print(a)

Python: while True:
    a = int(input())
    if  a == 0:
        break
    else:
        b = 1000-a
        c = b%500
        d = c%100
        e = d%50
        f = e%10
        g = f%5
        print(b//500+c//100+d//50+e//10+f//5+g)

Python: while True:
    try:
        a=list(map(int,input().split()))
        x=0
        y=0
        z=0
        u=0
        w=0
        
        g=1000-a[0]
        if g==1000:
            pass
        else:
            if g>=500:
                x=1
                g=g-500
            y=g//100
            g=g-100*y
            if g>=50:
                z=1
                g=g-50
            u=g//10
            g=g-10*u
            if g>=5:
                w=1
                g=g-5
            print(x+y+z+u+w+g)
    except:
        break;

Python: try:
    while True:
        n=int(input())
        m=1000-n
        i=0
        if m==1000:
            break
        else:
            i+=m//500
            m=m%500
            i+=m//100
            m=m%100
            i+=m//50
            m=m%50
            i+=m//10
            m=m%10
            i+=m//5
            m=m%5
            i+=m
        print(i)
except EOFError:
    pass

Python: c = [500, 100, 50, 10, 5, 1]
while True:
    n = int(input())
    x = 1000 - n
    if x == 1000:
        break
    a = 0
    for i in c:
        a += x // i 
        x %= i 
    print(a)

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

Python: while True:
	n = int(input())
	if n == 0:
		break
	m = 0
	c = 1000 - n
	while c != 0:
		if c >= 500:
			c = c - 500
			m = m + 1
		elif c >= 100:
			c = c - 100
			m = m + 1
		elif c >= 50:
			c = c - 50
			m = m + 1
		elif c >= 10:
			c = c - 10
			m = m + 1
		elif c >= 5:
			c = c - 5
			m = m + 1
		elif c >= 1:
			c = c - 1
			m = m + 1
	print(m)

Python: while True:
    t = int(input())
    if t==0:
        break
    n = (1000-t)//500+((1000-t)%500)//100+((1000-t)%100)//50+((1000-t)%50)//10+((1000-t)%10)//5+((1000-t)%5)
    print(n)

Python: while True:
    n, ans = 1000 - int(input()), 0
    if n == 1000:
        break
    for m in (500, 100, 50, 10, 5, 1):
        ans, n = ans+n//m, n%m
    print(ans)

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(price):
    change = 1000 - price
    total_coins = 0
    for coin in [500, 100, 50, 10, 5, 1]:
        coins, change = divmod(change, coin)
        total_coins += coins
    return total_coins


if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        else:
            print(solve(n))

Python: while True:
    a=int(input())
    if a==0:
        break
    b=((1000-a)//500)
    c=(((1000-a)-500*b)//100)
    d=(((1000-a)-500*b-100*c)//50)
    e=(((1000-a)-500*b-100*c-50*d)//10)
    f=(((1000-a)-500*b-100*c-50*d-10*e)//5)
    g=((1000-a)-500*b-100*c-50*d-10*e-5*f)
    print(b+c+d+e+f+g)

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

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

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

"""
import sys
from sys import stdin
input = stdin.readline


def count_coint(change):
    ans = 0
    coins = (500, 100, 50, 10, 5, 1)
    for c in coins:
        t = change // c
        ans += t
        change -= t * c
    return ans


def main(args):
    while True:
        payment = int(input())
        if payment == 0:
            break

        change = 1000 - payment
        result = count_coint(change)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

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

Python: def calc(n):
	a = 1000 - n
	y = [500, 100, 50, 10, 5, 1]
	ans = 0
	for i in y:
		ans += a // i
		a %= i
		if a == 0:
			return ans
def resolve():
	while True:
		v = int(input())
		if v == 0:
			return
		print(calc(v))
resolve()

Python: COINS = [500, 100, 50, 10, 5, 1]

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

print(total)

Python: while True :
    n = int(input())
    if n == 0 :
        break
    
    s = 1000 - n
    count = 0
    if s >= 500 :
        count += 1
        s = s - 500
    if s >= 100 :
        count += int(s / 100)
        s = int(s % 100)
    if s >= 50 :
        count += 1
        s = s - 50
    if s >= 10 :
        count += int(s / 10)
        s = int(s % 10)
    if s >= 5 :
        count += 1
        s = s - 5
    count += s
    print(count)

Python: while True:
    m=int(input())
    p=1000-m
    a=p//500
    x=p%500
    b=x//100
    y=x%100
    c=y//50
    z=y%50
    d=z//10
    o=z%10
    e=o//5
    f=o%5
    if m==0:
        break
    print(a+b+c+d+e+f)

Python: i=1
while True:
    x=int(input())
    if x==0:
        break
    x=1000-x
    a=x//500
    b=(x%500)//100
    c=(x%100)//50
    d=(x%50)//10
    e=(x%10)//5
    f=x%5
    print(a+b+c+d+e+f)
    i+=1

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

Python: while True:
    m = int(input())
    if m == 0:break
    n = 1000 - m
    a = n // 500
    n%=500
    b = n // 100
    n%=100
    c = n // 50
    n%=50
    d = n // 10
    n%=10
    e = n // 5
    n%=5
    print(a + b + c + d + e + n)

Python: # coding: utf-8
# Your code here!

while True:
    a = int(input())
    if a == 0 :
        break
    b = 1000 - a
    c = b //500
    d = b % 500
    e = d //100
    f = d % 100
    g = f //50
    h = f % 50
    i = h //10
    j = h %10
    k = j //5
    l = j %5
    print(c+e+g+i+k+l)

Python: while True:
    x=int(input())
    if x == 0:
        break
    a=(1000-x)//500
    b=(1000-x)%500//100
    c=(1000-x)%500%100//50
    d=(1000-x)%500%100%50//10
    e=(1000-x)%500%100%50%10//5
    f=(100-x)%500%100%50%10%5
    print(a+b+c+d+e+f)

Python: while True:
    x=int(input())
    if x==0:
        break
    a=1000-x
    b=a//500
    c=a%500
    d=c//100
    e=c%100
    f=e//50
    g=e%50
    h=g//10
    i=g%10
    j=i//5
    k=i%5
    print(b+d+f+h+j+k)

Python: i = 0

while True:
    n = int(input())
    x = 1000 - n
    if n == 0:
        break
    
    a = x//500
    x = x%500
    
    b = x//100
    x = x%100
    
    c = x//50
    x = x%50
    
    d = x//10
    x = x%10
    
    e = x//5
    
    f = x%5
    
    print(a+b+c+d+e+f)
    
    i += 1