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

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

Python: def co(n):
    a = int(1000-n)
    b = int(a//500)
    c = int((a%500)//100)
    d = int((a%100)//50)
    e = int((a%50)//10)
    f = int((a%10)//5)
    g = int((a%5)//1)
    sum = b+c+d+e+f+g
    print(sum)
for i in range(5):
    x = int(input())
    if x == 0:
        break
    co(x)

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

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-

x = 1000 - int(input())

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

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

print(ret)

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

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: while True:
    x=int(input())
    if x==0:
        break
    else:
        y=1000-x
        y1=y//500
        y2=(y-500*y1)//100
        y3=(y-500*y1-100*y2)//50
        y4=(y-500*y1-100*y2-50*y3)//10
        y5=(y-500*y1-100*y2-50*y3-10*y4)//5
        y6=(y-500*y1-100*y2-50*y3-10*y4-5*y5)//1
        z=y1+y2+y3+y4+y5+y6
        print(z)

Python: for i in range(5):
    a=int(input())
    A=1000-a
    x=A//500
    M=A%500
    y=M//100
    M=M%100
    z=M//50
    M=M%50
    w=M//10
    M=M%10
    u=M//5
    M=M%5
    
    if a==0: break

    print(x+y+z+w+u+M)

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

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

for l in [500, 100, 50, 10, 5, 1]: change(l)
print(c+o)

Python: def keisan(a) :
    p=1000-a
    otsurifh=p//500
    otsurih=(p-otsurifh*500)//100
    otsurifj=(p-otsurifh*500-otsurih*100)//50
    otsurij=(p-otsurifh*500-otsurih*100-otsurifj*50)//10
    otsurig=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10)//5
    otsurii=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10-otsurig*5)
    return(otsurifh+otsurih+otsurifj+otsurij+otsurig+otsurii)

for i in range(5):
    c=int(input())
    if c==0 : break
    b=keisan(c)
    print(b)

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

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

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

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

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

Python: #0521
while True:
    n = int(input())
    if n == 0:
        break
    x = 1000 - n
    cnt = 0
    if x >= 500:
        cnt += 1
        x = x - 500
    if x > 100:
        cnt = cnt + x//100
        x = x - (100 * (x//100))
    if x >= 50:
        cnt = cnt + x//50
        x = x - (50 * (x//50))
    if x >= 10:
        cnt = cnt + x//10
        x = x - (10 * (x//10))
    if x >= 5:
        cnt = cnt + x//5
        x = x - (5 * (x//5))
    print(cnt + x)

Python: def main():
    def coin_count(n):
        cnt = 0
        a, b, c, d, e, f = 0, 0, 0, 0, 0, 0
        n = 1000 - n
        if n >= 500:
            a = n // 500
            n = n - 500 * a
        if n >= 100:
            b = n // 100
            n = n - 100 * b
        if n >= 50:
            c = n // 50
            n = n - 50 * c
        if n >= 10:
            d = n // 10
            n = n - 10 * d
        if n >= 5:
            e = n // 5
            n = n - 5 * e
        f = n
        ans = a + b + c + d + e + f
        print(ans)

    while True:
        n = int(input())
        if n == 0:
            break
        coin_count(n)  

if __name__ == '__main__':
    main()