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

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

Python: def main():
    while True:
        N = int(input())
        if N == 0:
            return

        o = 1000 - N
        ans = 0
        coin = [500, 100, 50, 10, 5, 1]
        for c in coin:
            set = o // c
            ans += set
            o -= c * set

        print(ans)


if __name__ == '__main__':
    main()

Python: nyuuryoku=[]
while True:
	bbb=int(input())
	if bbb==0:	
		break
	a=1000-bbb
	gohyaku=int(a/500)
	hyaku=int((a-(500*gohyaku))/100)
	gojuu=int((a-(500*gohyaku)-(100*hyaku))/50)
	juu=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu))/10)
	go=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu)-(juu*10))/5)
	iti=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu)-(juu*10)-(go*5))/1)
	print(go+gohyaku+gojuu+hyaku+iti+juu)

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(b+a)

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

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:
        x=1000-X
        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)
    else:
        break

Python: import math
while True:
    n=0
    a=int(input())
    if a==0:
        break
    
    b=1000-a
    
    if b>=500:
        n+=1
        b-=500
    if b>=100:
        x=math.floor(b/100)
        n+=x
        b-=x*100
    if b>=50:
        n+=1
        b-=50
    if b>=10:
        x=math.floor(b/10)
        n+=x
        b-=x*10
    if b>=5:
        n+=1
        b-=5
    if b>=1:
        n+=b
    print(n)

Python: i=0
while True:
    X=int(input())
    if X==0:
        break
    x=1000-X
    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:
    P = int(input())
    if P == 0:
        break
    
    r = 1000 - P
    
    _500 = r // 500
    _100 = (r % 500) // 100
    _50 = (r % 100) // 50
    _10 = (r % 50) // 10
    _5 = (r % 10) // 5
    _1 = (r % 5)
    
    print(_500+_100+_50+_10+_5+_1)

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)]
print(changes)
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: i=1
while True:
    x=int(input())
    if x==0:
        break
    x=1000-x
    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)
    i+=1

Python: def oturi(now, kingaku):
    coin = now // kingaku
    if coin:
        now -= coin * kingaku
    return now, coin

while True:
    n = int(input())
    if n == 0:
        break
    now = 1000 - n
    coin = 0
    now, c = oturi(now, 500)
    coin += c
    now, c = oturi(now, 100)
    coin += c
    now, c = oturi(now, 50)
    coin += c
    now, c = oturi(now, 10)
    coin += c
    now, c = oturi(now, 5)
    coin += c
    now, c = oturi(now, 1)
    coin += c
    print(coin)

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

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: coin = [500, 100, 50, 10, 5, 1]; ans = 0;
rest = 1000-int(raw_input())
for i in range(6):
    while(rest>=coin[i]):
        rest-=coin[i]; ans+=1;
print(str(ans))

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

    ans = 0
    while(n<=500):
        n += 500
        ans += 1
    while(n<=900):
        n += 100
        ans += 1
    while(n<=950):
        n += 50
        ans += 1
    while(n<=990):
        n += 10
        ans += 1
    while(n<=995):
        n += 5
        ans += 1
    while(n<=999):
        n += 1
        ans += 1

    print(ans)

Python: while True:
    n=int(input())
    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)