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

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while (cin >> n && n) {
        int cost = 1000 - n;
        int n1 = cost / 500;
        cost -= 500 * (cost / 500);
        int n2 = cost / 100;
        cost -= 100 * (cost / 100);
        int n3 = cost / 50;
        cost -= 50 * (cost / 50);
        int n4 = cost / 10;
        cost -= 10 * (cost / 10);
        int n5 = cost / 5;
        cost -= 5 * (cost / 5);
        cout << n1 + n2 + n3 + n4 + n5 + cost << '\n';
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu;
  
  cin >> money;
  oturi = 1000 - money;

  for(int i = 1000;oturi > 0;i / 10){
    oturi %= i;
    if(oturi >= i/10){
      oturi / (i/10) >= 5 ? maisu += oturi / (i/10) - 4 : maisu += oturi / (i/10);
    }
  }
    cout << maisu << endl;
    
    return 0;
  }

C++: #include <iostream>
#include <vector>
using namespace std;

int main(){
  int input;
  int c[6]={500,100,50,10,5,1};

  while(true){
    cin >> input;
    if(input == 0) break;
    input = 1000-input;
    int n=0;
    for(int i=0;i<6;i++){
      n+=input/c[i];
      input = input%c[i];
    }
    cout << n << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
    while(a!=0){
	cin>>a;
	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))/1;
        cout<<b+c+d+e+f+g<<endl;}
	return 0;
}

C++: #include<iostream>
using namespace std;

int coin[6] = {500,100,50,10,5,1};

int main(){
  int n;
  while(cin >> n,n){
    n = 1000-n;
    int pos = 0, ans = 0;
    while(n){
      if(n>=coin[pos]){
	n -= coin[pos];
	ans++;
      }else{
	pos++;
      }
    }
    cout << ans << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

int coin[]={500,100,50,10,5,1};

int main(){
    int n;
    while(cin>>n,n){
            
        n=1000-n;
        int ans=0;
    
        for(int i=0;i<6;i++){
            ans+=n/coin[i];
            n%=coin[i];
        }
        
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
    int amount;
    int change[] = {500, 100, 50, 10, 5, 1};

    while (scanf("%d", &amount), amount){
        int money = 1000;
        money -= amount;
        int count = 0;
        int i = 0;

        while (i < 6){
            if (money - change[i] >= 0){
                money -= change[i];
                count++;
            }
            else {
                i++;
            }
        }

        printf("%d\n", count);
    }

    return (0);
}

C++: #include<iostream>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num[10];
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

		cost_return = 1000 - cost_input[i];
		num[i] = 0;

		if (cost_return < 5) {
			num[i] = cost_return;
			continue;
		}
		else {
			if (cost_return < 10) {
				num[i] = 1 + cost_return - 5;
				continue;
			}
		}


		if (cost_return >= 500) {
			++num[i];
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num[i];
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num[i];
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num[i];
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num[i];
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num[i];
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
		
	}
	
	for (int i = 0; i < j; ++i) {
		CO num[i] E
	}

	
}

C++: #include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
int main(){
	int n;
	int change[] = {500,100,50,10,5,1};
	while(scanf("%d",&n),n){
		n = 1000-n;
		int ans = 0;
		while(n > 0){
			ans++;
			for(int i = 0; i < 6; i++){
				if(n - change[i] >= 0){
					n -= change[i];
					break;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int money;
    while( cin >> money ){

    int coin_count=0;
    int rest =1000;

    rest -= money;
    int tmp =0;

    coin_count += rest /500;
    rest = rest % 500;

    coin_count += rest /100;
    rest = rest % 100;

    coin_count += rest /50;
    rest = rest % 50;

    coin_count += rest /10;
    rest = rest % 10;

    coin_count += rest /5;
    rest = rest % 5;

    coin_count += rest /1;
    cout << coin_count << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>

using namespace std;

vector<int> ans;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		int change = 1000 - n;
		int coin[] = {500,100,50,10,5,1};
		
		int tans = 0;
		for(int i = 0;i < 6;i++){
			int maisu = change / coin[i];
			if(maisu != 0){
				tans += maisu;
				change -= coin[i] * maisu;
			}
		}
		ans.push_back(tans);
	}
	
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin >> n; n = 1000 - n;
	int r = 0;
	r += n / 500; n %= 500;
	r += n / 100; n %= 100;
	r += n / 50; n %= 50;
	r += n / 10; n %= 10;
	r += n / 5; n %= 5;
	r += n;
	cout << r << endl;
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int a,i=0,b;
  while(1){
    i=0;
    cin>>a;
    if(a==0)break;
    b=1000-a;
    if(b>=500){
      i=b/500;
      b=b%500;
    }
    if(b>=100){
      i+=b/100;
      b=b%100;
    }
    if(b>=50){
      i+=b/50;
      b=b%50;
    }
    if(b>=10){
      i+=b/10;
      b=b%10;
    }
    if(b>=5){
      i+=b/5;
      b=b%5;
    }
    if(b>=1){
      i+=b/1;
    }
    cout<<i<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt=0,div[6]=[500,100,50,10,5,1];
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
for(i=0;i<6;i++){
if((price/div[i])!=0){
cnt+=(price/div[i]);
price-=(price/div[i])*div[i];
}
}
cout<<cnt<<endl;
cnt=0;
}
return 0;
}