Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

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)

Python: while True:
    money=int(input())
    
    if money>0:
        oturi=1000-money
        a=oturi//500
        aa=oturi-a*500
        b=aa//100
        bb=aa-b*100
        c=bb//50
        cc=bb-c*50
        d=cc//10
        dd=cc-d*10
        e=dd//5
        ee=dd-e*5
        f=ee
        print(a+b+c+d+e+f)
    
    else:
        break

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

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

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

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

Python: while True:
    n=int(input())
    if n==0:
        break
    else:
        a=1000-n
        i=a%10
        if i>=5:
            i=1+i-5
        else:
            pass
        j=a//10
        j2=j%10
        if j2>=5:
            j2=1+j2-5
        else:
            pass
        h=a//100
        if h>=5:
            h=1+h-5
        else:
            pass
    print(i+j2+h)

Python: while True:
    N=int(input())
    k=1000-N
    f=int(k/500)
    h=int((k%500)/100)
    i=int(((k%500)%100)/50)
    t=int((((k%500)%100)%50)/10)
    v=int(((((k%500)%100)%50)%10)/5)
    o=int((((((k%500)%100)%50)%10)%5)/1)

    if N==0:
        break
    print(f+h+i+t+v+o)

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

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: while True:
    coin=0
    n=int(input())
    if n==0:
        break
    else:
        money=1000-n
        if money//500>=1:
            coin1=int(money//500)
            money-=500*coin1
            coin+=coin1
        else:
            pass
        if money//100>=1:
            coin2=int(money//100)
            money-=100*coin2
            coin+=coin2
        else:
            pass
        if money//50>=1:
            coin3=int(money//50)
            money-=50*coin3
            coin+=coin3
        else:
            pass
        if money//10>=1:
            coin4=int(money//10)
            money-=10*coin4
            coin+=coin4
        else:
            pass
        if money//5>=1:
            coin5=int(money//5)
            money-=5*coin5
            coin+=coin5
        else:
            pass
        if money//1>=1:
            coin6=int(money//1)
            coin+=coin6
        else:
            pass
        
        print(coin)

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