Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

Python: for i in range(5):
    e  = int(input())
    if e == 0:
        break
    e500 = (1000 - e)//500
    e100 = (1000 - e)%500//100
    e50 = (1000 - e)%500%100//50
    e10 = (1000 - e)%500%100%50//10
    e5 = (1000 - e)%500%100%50%10//5
    e1 = (1000 - e)%500%100%50%10%5//1
    print(e500+e100+e50+e10+e5+e1)

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

Python: for i in range(5):
    s=0
    q=0
    n=int(input())
    if n==0:
        break
    n=1000-n
    if n>=500:
        n-=500
        s+=1
    if n>=100:
        q=n//100
        n-=100*q
        s+=q
    if n>=50:
        n-=50
        s+=1
    if n>=10:
        q=n//10
        n-=10*q
        s+=q
    if n>=5:
        n-=5
        s+=1
    if n>=1:
        q=n//1
        s+=q
    print(s)

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

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

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

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: # coding: utf-8
# Your code here!

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

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

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

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

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: i = 0
while i < 5:
    fee = int(input())
    if fee == 0:
        break
    
    refee = 1000 - fee
    
    C500 = refee     // 500
    C100 = refee%500 // 100
    C50  = refee%100 // 50
    C10  = refee%50  // 10
    C5   = refee%10  // 5
    C1   = refee%5
    
    sum = C500 + C100 + C50 + C10 + C5 + C1
    print(sum)

Python: while True :
    i = int(input())
    a = 0
    if i == 0 :
        break
    else :
        b = 1000 - i
        
        if b >= 500 :
            a += 1
            b -= 500
        
        while b >= 100 :
            a += 1
            b -= 100
        
        while b >= 50 :
            a += 1
            b -= 50
            
        while b >= 10 :
            a += 1
            b -= 10
            
        while b >= 5 :
            a += 1
            b -= 5
            
        a += b   
    
    print(a)

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

Python: N=0
for i in range(7):
  N=int(input())
  if N==0:
    break
  N=1000-N
  print(N//500+(N//100)%5+(N//50)%2+(N//10)%5+(N//5)%2+N%5)

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

Python: while True:
    i=int(input())
    if i==0:
        break
    s1=(1000-i)//500
    s2=(1000-i)%500//100
    s3=(1000-i)%500%100//50
    s4=(1000-i)%500%100%50//10
    s5=(1000-i)%500%100%50%10//5
    s6=(1000-i)%500%100%50%10%5//1
    print(s1+s2+s3+s4+s5+s6)

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:
    Y = int(input())
    if Y == 0:
        break
    X = 1000 - Y
    a = X // 500
    X = X - a * 500
    b = X // 100
    X = X - b * 100
    c = X // 50
    X = X - c * 50
    d = X // 10
    X = X - d * 10
    e = X // 5
    X = X - e * 5
    f = X // 1
    
    print(a+b+c+d+e+f)

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

    m1=y//500
    m2=(y-(500*m1))//100
    m3=((y-(500*m1))-(100*m2))//50
    m4=(((y-(500*m1))-(100*m2))-(50*m3))//10
    m5=((((y-(500*m1))-(100*m2))-(50*m3))-(10*m4))//5
    m6=((((y-(500*m1))-(100*m2))-(50*m3))-(10*m4))-5*m5
    
    z=m1+m2+m3+m4+m5+m6
    
    print(z)

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: for i in range(5):
    a=int(input())
    if a == 0:
        break
    b=1000-a
    if b > 500:
        c=b-(500*(b//500))
        d=c-(100*(c//100))
        e=d-(50*(d//50))
        f=e-(10*(e//10))
        g=f-(5*(f//5))
        print((b//500)+(c//100)+(d//50)+(e//10)+(f//5)+g)
    elif b > 100:
        g=b-(100*(b//100))
        h=g-(50*(g//50))
        i=h-(10*(h//10))
        j=i-(5*(i//5))
        print((b//100)+(g//50)+(h//10)+(i//5)+(j))
    elif b > 50:
        k=b-(50*(b//50))
        l=k-(10*(k//10))
        m=l-(5*(l//5))
        print((b//50)+(k//10)+(l//5)+(m))
    elif b > 10:
        n=b-(10*(b//10))
        o=n-(5*(n//5))
        print((b//10)+(n//5)+(o))
    elif b > 5:
        p=b-(5*(b//5))
        print((b//5)+(p))
    else:
        print(b)

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

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

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: for i in range(5):
    a=int(input())
    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
    if a==0:break
    print(b+c+d+e+f+g)

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