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

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

Python: x = int(input())
while x != 0:
    y = 1000 - x
    a = y // 500
    A = y % 500
    b = A // 100
    B = A % 100
    c = B // 50
    C = B % 50
    d = C // 10
    D = C % 10
    e = D // 5
    E = D % 5
    print(a + b + c + d + e + E)
    x = int(input())

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:
    price = int(input())
    change = 1000 - price
    n = 0
    if price == 0:
        break
    if change >= 500:
        change -= 500
        n += 1
    while change >= 100:
        change -= 100
        n += 1
    if change >= 50:
        change -= 50
        n += 1
    while change >= 10:
        change -= 10
        n += 1
    if change >= 5:
        change -= 5
        n += 1
    while change >= 1:
        change -= 1
        n += 1
        
    print(n)

Python: while True:
    x = int(input())
    if x==0 :
        break
    if x > 0:
        x = 1000 - x
        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)

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

Python: coins = (500, 100, 50, 10, 5, 1)

def count(x, y):
    ret = 0
    while x >= y:
        x -= y
        ret += 1
    return x, ret

while True:
    n = input()
    if n == 0:
        break
    ans = 0
    n = 1000 - n
    for val in coins:
        n,  t = count(n, val)
        ans += t

    print(ans)

Python: while True:
    N = int(input())
    if N == 0:
        break
    ans = 0
    change = 1000 - N
    while change >= 500:
        change -= 500
        ans += 1
    while change >= 100:
        change -= 100
        ans += 1
    while change >= 50:
        change -= 50
        ans += 1
    while change >= 10:
        change -= 10
        ans += 1
    while change >= 5:
        change -= 5
        ans += 1
    ans += change
    print(ans)

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

Python: while 1:
    try:
        n=int(input())
        if n==0:break
        change=1000-n
        ans=0
        kouka=[500,100,50,10,5,1]
        for i in kouka:
            ans+=change//i
            change=change%i
        print(ans)
    except:break

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

Python: while True:
    n = int(input())
    if n == 0:
        break
    chg = 1000 - n
    m = [500, 100, 50, 10, 5, 1]
    cnt = [0,0,0,0,0,0]
    for i in range(len(m)):
        cnt[i] = chg//m[i]
        chg -=cnt[i]*m[i]
    ans = 0
    for i in range(len(cnt)):
        ans += cnt[i]
    print(ans)

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

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

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

Python: 
for i in range(5):
    x=int(input())
    a=1000-x
    if x!=0:
        b=0
        b+=(a//500)#500
        
        b+=(a%500)//100#100
        
        b+=((a%500)%100)//50#50
        
        b+=(((a%500)%100)%50)//10#10
        
        b+=((((a%500)%100)%50)%10)//5
        
        b+=((((a%500)%100)%50)%10)%5
    elif x==0:
        break
        
    print(b)

Python: def cash_co(change):
    ans = 0
    a = (500, 100, 50, 10, 5, 1)
    for i in a:
        co = change // i
        ans += co
        change = change - i * co
    return ans
        

while True:
    n = int(input())
    if n == 0:
        break
        
    change = 1000 - n
    result = cash_co(change)
    print(result)

Python: while True:
    kei = 0
    i = int(input())
    if i == 0:
        break
    else:
        num = 1000 - i
        if num >= 500:
            num %= 500
            kei += 1
        if num >= 100:
            num1 = num // 100
            kei += num1
            num %= 100
        if num >= 50:
            num %= 50
            kei += 1
        if num >= 10:
            num1 = num // 10
            kei += num1
            num %= 10
        if num >= 5:
            num %= 5
            kei += 1
        if num >= 1:
            num1 = num // 1
            kei += num1
    print(kei)

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

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

    else: 
        otsuri=1000-x;
        a=otsuri%500
        b=a%100
        c=b%50
        d=c%10
        e=d%5
        maisuu=otsuri//500+a//100+b//50+c//10+d//5+e
        print(maisuu)

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

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: while True:
    money=int(input())
    
    if money==0:
        break
    
    a=1000-money
    A=a//500
    b=a-500*A
    B=b//100
    c=b-100*B
    C=c//50
    d=c-50*C
    D=d//10
    e=d-D*10
    E=e//5
    F=e-E*5
    
    print(A+B+C+D+E+F)

Python: for i in range(5):
  x=int(input())
  if x==0:break
  else:
    s=1000-x
    a=s//500
    a1=s-a*500
    b=a1//100
    b1=a1-b*100
    c=b1//50
    c1=b1-c*50
    d=c1//10
    d1=c1-d*10
    e=d1//5
    f=d1-e*5
    sum=a+b+c+d+e+f
  print(sum)