Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"bufio"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	buf = make([]byte, 1000)
)

func scanText() string{
	sc.Scan()
	return sc.Text()
}

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
//  template end

var (
	coins = [6]int{500, 100, 50, 10, 5, 1}
)

func f(data int) {
	ans := 0
	change := 1000 - data
	for _, v := range coins {
		for ;v <= change; {
			change -= v
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	sc.Buffer(buf, 10000)
	for{
		data := scanInt()
		if data == 0 {
			break
		}
		f(data)
	}
}

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

Python: while True:
    x=int(input())
    if x==0:
        break
    else:
        y=1000-x
        y1=y//500
        y2=(y-500*y1)//100
        y3=(y-500*y1-100*y2)//50
        y4=(y-500*y1-100*y2-50*y3)//10
        y5=(y-500*y1-100*y2-50*y3-10*y4)//5
        y6=(y-500*y1-100*y2-50*y3-10*y4-5*y5)//1
        z=y1+y2+y3+y4+y5+y6
        print(z)

Python: for i in range(5):
    a=int(input())
    A=1000-a
    x=A//500
    M=A%500
    y=M//100
    M=M%100
    z=M//50
    M=M%50
    w=M//10
    M=M%10
    u=M//5
    M=M%5
    
    if a==0: break

    print(x+y+z+w+u+M)

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

Python: 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(c+o)

Python: def keisan(a) :
    p=1000-a
    otsurifh=p//500
    otsurih=(p-otsurifh*500)//100
    otsurifj=(p-otsurifh*500-otsurih*100)//50
    otsurij=(p-otsurifh*500-otsurih*100-otsurifj*50)//10
    otsurig=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10)//5
    otsurii=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10-otsurig*5)
    return(otsurifh+otsurih+otsurifj+otsurij+otsurig+otsurii)

for i in range(5):
    c=int(input())
    if c==0 : break
    b=keisan(c)
    print(b)

Python: while True:
    s=int(input())
    if s==0:
        break
    a=1000-s
    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: coin=[500,100,50,10,5,1]
while True:
    money=int(input())
    if money==0:
        break
    ans=0
    m=1000-money
    for i in coin:
        ans+=m//i
        m=m%i
    print(ans)

Python: # coding: utf-8
# Your code here!
while True:
    n=int(input())
    if 0<=n<1000:
        if n==0:
            break
        else:
            sum=0
            
            sum+=(1000-n)//500
            sum+=(1000-n)%500//100
            sum+=(1000-n)%500%100//50
            sum+=(1000-n)%500%100%50//10
            sum+=(1000-n)%500%100%50%10//5
            sum+=(1000-n)%500%100%50%10%5//1
            
    print(sum)

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

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

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

Python: #0521
while True:
    n = int(input())
    if n == 0:
        break
    x = 1000 - n
    cnt = 0
    if x >= 500:
        cnt += 1
        x = x - 500
    if x > 100:
        cnt = cnt + x//100
        x = x - (100 * (x//100))
    if x >= 50:
        cnt = cnt + x//50
        x = x - (50 * (x//50))
    if x >= 10:
        cnt = cnt + x//10
        x = x - (10 * (x//10))
    if x >= 5:
        cnt = cnt + x//5
        x = x - (5 * (x//5))
    print(cnt + x)

Python: def main():
    def coin_count(n):
        cnt = 0
        a, b, c, d, e, f = 0, 0, 0, 0, 0, 0
        n = 1000 - n
        if n >= 500:
            a = n // 500
            n = n - 500 * a
        if n >= 100:
            b = n // 100
            n = n - 100 * b
        if n >= 50:
            c = n // 50
            n = n - 50 * c
        if n >= 10:
            d = n // 10
            n = n - 10 * d
        if n >= 5:
            e = n // 5
            n = n - 5 * e
        f = n
        ans = a + b + c + d + e + f
        print(ans)

    while True:
        n = int(input())
        if n == 0:
            break
        coin_count(n)  

if __name__ == '__main__':
    main()

Python: while True:
    n = int(input())
    charge = 1000 - n
    
    if n == 0:
        break

    count_coin = 0
    coin_kind =[1,5,10,50,100,500]

    for i in range(1,7):
        t = charge // coin_kind[-i]
        charge -= t * coin_kind[-i]
        count_coin += t

    print(count_coin)

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

Python: price=int(input())
while price!=0:
    change=1000-price
    if change//500==1:
        fiveh=1
        change-=500
    else:
        fiveh=0
    if change//100>0:
        hundred=change//100
        change=change%100
    else:
        hundred=0
    if change//50>0:
        fifty=change//50
        change=change%50
    else:
        fifty=0
    if change//10:
        ten=change//10
        change=change%10
    else:
        ten=0
    if change//5:
        five=change//5
        change=change%5
    else:
        five=0
    one=change    
    print(fiveh+hundred+fifty+ten+five+one)  
    price=int(input())
else:
    pass

Python: while True:
    a = int(input())
    if a == 0:break

    A = [500,100,50,10,5,1]
    a= 1000 - a
    ans = 0
    for b in A:
        ans+=a // b
        a%=b
    print(ans)

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

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

Python: taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]

for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)