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())
    if n == 0:
        break
    oturi = 1000 - n
    li = [500,100,50,10,5,1]
    cnt = [0,0,0,0,0,0]
    for i in range(len(li)):
        cnt[i] = oturi//li[i]
        oturi -= cnt[i]*li[i]
    ans = 0
    for i in range(len(cnt)):
        ans += cnt[i]
    print(ans)

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		N = 1000 - N;
		int ans = 0;
		set<int>s;
		s = { 500,100,50,10,5,1 };
		for (auto m : s) {
			ans += N / m;
			N /= m;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>

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

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {

  int value,change;
  int coins;


  while(1) {

    cin >> value;

    if(value==0) break;

    coins=0;
    change=1000-value;

    coins+=change/500;
    change%=500;

    coins+=change/100;
    change%=100;

    coins+=change/50;
    change%=50;

    coins+=change/10;
    change%=10;

    coins+=change/5;
    change%=5;

    coins+=change/1;
    change%=1;

    cout << coinsツ　<< endl;

  }

  return 0;

}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>

using namespace std;


int combart(int a) {
	int maisuu = 0;
	if (a >= 5) {
		maisuu++;
		a -= 5;
	}
	return maisuu + a;
}

int main(){

	int siharai;
	int oturi;

	while (1) {
		cin >> siharai;
		if (siharai == 0)break;

		oturi = 1000 - siharai;

		int hyaku = oturi / 100;
		int juu = (oturi % 100) / 10;
		int iti = oturi % 10;

		cout << combart(hyaku) + combart(juu) + combart(iti) << endl;
	}


//	system("pause");
    return 0;
}

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


int main(){
    while (1){
	int n;
	
	int m = 0;
	cin >> n;
	if (n == 0) break;
	n = 1000 - n;
	
	while (n >= 500){
	    m++;
	    n -= 500;
	    cout << n << " " << m << endl;
	}
	while (n >= 100){
	    m++;
	    n -= 100;
	    cout << n << " " << m << endl;
	}
	while (n >= 50){
	    m++;
	    n -= 50;
	    cout << n << " " << m << endl;
	}
	while (n >= 10){
	    m++;
	    n -= 10;
	    cout << n << " " << m << endl;
	}
	while (n >= 5){
	    m++;
	    n -= 5;
	    cout << n << " " << m << endl;
	}
	while (n >= 1){
	    m++;
	    n -= 1;
	}

	cout << m << endl;
    
    }
}

C++: main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
}

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

}

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n && n != 0){
	
		int a = 1000 - n;
		int cnt = 0;
		for(int i = 0; i < 6; ++i){
			while(a >= coin[i]){
				a -= coin[i];
				++cnt;
			}
		}
		
		cout << cnt << endl;
	}

	return 0;
}

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

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

int main() {

	int change, coins;

	while (cin >> change, change) {
		change = 1000 - change;

		coins = 0;
		for (int i = 0; i < 6; ++i) {
			if (change >= coin[i]) {
				coins += change / coin[i];
				change %= change / coin[i];
				if (!change)
					break;
			}
		}
		cout << coins << endl;
	}
	return 0;
}

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

int change[6]={1,5,10,50,100,500};
int cnt;
int n;

int main(){
	cin >> n;
	n = 1000-n;
	for( int i = 5; i >= 0; i-- ){
		while(n>=change[i]){
			n-=change[i];
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main(){
  int money;
  while(cin >> money && money !=0){
    int count =0;
    int res = 1000 - money;
    for(int i=0;i<3;i++){
      //      cout << res << endl;
      count +=res %10;
      if(res % 10 >4){ count -= 4;}
      res /=10;
    }
    cout << count << endl;
  }
}

C++: #include<cstdio>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int price,change;
    int money[6]={500, 100, 50, 10, 5, 1};
    while(1){
    int cnt=0;
    cin >> price;
    if(price == 0)break;
    change = 1000 - price;
    for(int i = 0;i < 6;i++){
        while(1){
            if(change >= money[i]){
                change -= money[i];
                cnt++;
            }
            else break;
        }
    }
    cout << cnt << endl;
    }
    return 0;
}