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: coins=[500,100,50,10,5,1]
while 1:
    v=int(input())
    if v==0:
        break
    else:
        change=1000-v
        cnt=0
        for coin in coins:
            c=change//coin
            if c!=0:
                cnt+=c
                change-=coin*c
        print(cnt)

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

Python: 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(int(sum))

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

Python: def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

while True:
    o= int(input())
    if o== 0: break
    c, o= 0, 1000-o
    for l in [500, 100, 50, 10, 5, 1]: change(l)
    print(c+o)

Python: # AOJ 0521: Change
# Python3 2018.6.30 bal4u

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: x = int(input())
while x != 0:
    y = 1000 - x
    a = y//500
    b = (y-500*a)//100
    c = (y-(500*a+100*b))//50
    d = (y-(500*a+100*b+50*c))//10
    e = (y-(500*a+100*b+50*c+10*d))//5
    f = (y-(500*a+100*b+50*c+10*d+5*e))//1
    g = a+b+c+d+e+f
    print(g)
    x = int(input())

Python: while True:
    n=int(input())
    if n==0:
        break
    a=(1000-n)//500
    b=(1000-n-(500*a))//100
    c=(1000-n-(500*a)-(100*b))//50
    d=(1000-n-(500*a)-(100*b)-(50*c))//10
    e=(1000-n-(500*a)-(100*b)-(50*c)-(10*d))//5
    f=(1000-n-(500*a)-(100*b)-(50*c)-(10*d)-(5*e))//1
    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: 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: coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
    while True:
        p = int(input())
        if p == 0:
            break
        ch = 1000 - p

        count = 0
        for coin in coins:
            n = ch // coin
            ch -= coin * n
            count += n
        
        print(count)

Python: while 1:
    n = int(input())
    if n == 0:
        break
    else:
        change = 1000-n
        sum_coin = 0
        coin = [500,100,50,10,5,1]

        for i in coin:
            r = change // i
            change %= i
            sum_coin += r
    
        print(sum_coin)

Python: 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: 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: 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: #!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

    ret = 0
    for coin in coins:
        n = x//coin
        x = x - n*coin
        ret += n

    print(ret)

Python: a=(500,100,50,10,5)
while 1:
    b,c=1000-int(input()),0
    if b==1000:break
    for i in a:
        d,b=divmod(b,i)
        c+=d
    print(b+c)

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)

Python: #Volume5-0521
while True:
  nedan = input()
  if nedan == str(0):
    break
  o = str(1000 - int(nedan))
  m = int(0)
  if int(nedan) > 990:
    n = int(1)
  elif int(nedan) > 900:
    n = int(2)
  else:
    n = int(3)
  for a in range(n):
    if int(o[a]) < 5:
      m = m+int(o[a])
    else:
      m = m+int(o[a])-4
  print(m)

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

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

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)