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

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

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 1:
    n = int(input())
    if n == 0:
        break
    i = 0
    a=1000-n
    if a>=500:
        a = a-500
        i =i+1
    if a>=100:
        b = a//100
        i = i+b
        a = a-(100*b)
    if a>=50:
        i = i+1
        a = a-50
    if a>=10:
        b = a//10
        i = i+b
        a = a-(10*b)
    if a>=5:
        i = i+1
        a = a-5
    i = i+a
    print(i)

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

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

Python: while True:
    x=int(input())
    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
    n=a+b+c+d+e+f
    if x==0:
        break
    
    print(n)

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

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

Python: coin = [500, 100, 50, 10, 5, 1];
while(1):
    ipt = int(raw_input())
    if ipt==0: break
    ans = 0; rest = 1000-ipt;
    for i in range(6):
        while(rest>=coin[i]):
            rest-=coin[i]; ans+=1;
    print(str(ans))

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

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