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: 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)

Python: import sys

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

for i in sys.stdin:
    if int(i) == 0:
        break

    n =1000-int(i)
    cnt = 0

    while n != 0:
        for i in range(len(coins)):
            if n >= coins[i]:
                n = n-coins[i]
                break
        cnt += 1

    print(cnt)

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

def solve(n):
    t=1000-n
    cnt=0
    for i in range(len(c)):
        while t//c[i]>0:
            t-=c[i]
            cnt+=1
    return cnt


for i in range(5):
    n=int(input())
    if n==0:exit()
    print(solve(n))

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

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

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: while True:
    n = int(input())
    if n >= 1:
        x = 1000 - n
        a = x%500
        b = a%100
        c = b%50
        d = c%10
        e = d%5
        y = x//500 + a//100 + b//50 + c//10 + d//5 +e//1
        print(y)
    if n == 0:
        break

Python: import sys

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

for i in sys.stdin:
    if int(i) == 0:
        break

    n =1000-int(i)
    c = [ i for i in range(n+1) ]
    for i in range(len(coins)):
        coin = coins[i]
        if coin <= n:
            c[coin] = 1
            coins.append(coin)

    for coin in coins:
        for p in range(coin+1, n+1):
            minc = c[p]
            if minc == 1:
                continue
            c[p] = c[p-coin]+1 if minc > c[p-coin] + 1 else minc

    print(c[n])

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

Python: #!/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)

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

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

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

Python: def main():
    N = 1000 - int(input())
    while N != 1000:
        ans = 0
        while N >= 500:
            ans += 1
            N -= 500
        while N >= 100:
            ans += 1
            N -= 100
        while N >= 50:
            ans += 1
            N -= 50
        while N >= 10:
            ans += 1
            N -= 10
        while N >= 5:
            ans += 1
            N -= 5
        while N >= 1:
            ans += 1
            N -= 1
        print(ans)
        N = 1000 - int(input())

if __name__ == '__main__':
    main()

Python: 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)

Python: coins = (500, 100, 50, 10, 5, 1)
while True:
    n = int(input())
    if not n:
        break
    m, c = 0, 1000 - n
    for coin in coins:
        mt, c = divmod(c, coin)
        m += mt
        if not c:
            break
    print(m)

Python: while True:
    m=int(input())
    p=1000-m
    y500=p//500
    x500=p%500
    y100=x500//100
    x100=x500%100
    y50=x100//50
    x50=x100%50
    y10=x50//10
    x10=x50%10
    y5=x10//5
    x5=x10%5
    if m==0:
        break
    print(y500+y100+y50+y10+y5+x5)

Python: c, o= 0, 1000-int(input())
if o>= 500:
    o, c= o-500, c+1
if o>= 100:
    t= o//100
    o, c= o-(100*t), c+t
if o>= 10:
    t= o//10
    o, c= o-(10*t), c+t
if o>= 5:
    t= o//5
    o, c= o-(5*t), c+t
print(c)

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: i = 1
while i <= 5:
    x = int(input())
    if x == 0:
        break
    y = 1000 - x
    c_1 = y//500
    c_2 = y%500//100
    c_3 = y%500%100//50
    c_4 = y%500%100%50//10
    c_5 = y%500%100%50%10//5
    c_6 = y%500%100%50%10%5//1
    print(c_1+c_2+c_3+c_4+c_5+c_6)

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

Python: while True:
    n=int(input())
    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: i=0
l = [int(input()) for _ in range(5)]
while i<5:
    if(l[i]==0):
        break
    else:    
        a=1000-l[i]
        b=a//500  
        c=(a%500)//100   
        d=((a%500)%100)//50  
        e=(((a%500)%100)%50)//10
        f=((((a%500)%100)%50)%10)//5
        g=(((((a%500)%100)%50)%10)%5)//1
        print(b+c+d+e+f+g)
        i=i+1

Python: 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)