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;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int solve(int n){
	n=1000-n;
	int ans=0;

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

	for(int i=0;i<6;++i) while(n>=change[i]) n-=change[i],ans++;
		
	return ans;
}

int main(void){
	int n;
	while(cin >>n,n){
		cout << solve(n) << endl;
	}
	return 0;
}

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

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

	int coins[6] = { 500,100,50,10,5,1 };
int main() {
	while (1)
	{
	int n, ans = 0;
	cin >> n;
	if (n == 0)break;
	n = 1000 - n;
	for (int i = 0; i < 6; i++)
	{
		ans += n / coins[i];
		n %= coins[i];
	}
	cout << ans << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int s=0,h=0,ft=0,t=0,f=0,o=0,money=1000,genkin,sum=0;
	scanf("%d",&genkin);
	money=money-genkin;
	s=money/500;
	money=money-s*500;
	h=money/100;
	money=money-h*100;
	ft=money/50;
	money=money-ft*50;
	t=money/10;
	money=money-t*10;
	f=money/5;
	money=money-f*5;
	o=money/1;
	sum=s+h+ft+t+f+o;
	printf("%d\n",sum);

	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
    int m[] = {500,100,50,10,5,1};
    while(1){
    int n;
    scanf("%d",&n);
    if(n == 0)
        break;
    n = 1000 - n;
    
    int c = 0;int i = 0;
    while(n > 0){
        if(n < m[i]){
            i++;
        }else{
            n -= m[i];
            c++;
        }
    }
    printf("%d\n",c);
    }
    return 0;
}

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

int main()
{
int a,b,c;
a=0;
cin>>c;
b=1000-c;

while(b>=500){
a++;
b=b-500;
}
while(b>=100){
a++;
b=b-100;
}
while(b>=50){
a++;
b=b-50;
}
while(b>=10){
a++;
b=b-10;
}
while(b>=5){
a++;
b=b-5;
}
while(b>=1){
a++;
b=b-1;
}
cout<<a<<'\n';
return 0;
}

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

int main(){
	int change, pay, cnt;
	while(true){
		cin>>pay; if(pay==0) break;
		cnt=0;
		change = 1000 - pay;
		cnt+=  change / 500 ;
		cnt+= (change / 100) %5;
		cnt+= (change / 50)  %2;
		cnt+= (change / 10)  %5;
		cnt+= (change / 5)   %2;
		cnt+=  change 	   %5;
		cout<<cnt<<endl;
	}
	return 0;
}

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

C++: #include <iostream>

int main() {
	int a,coin = 0;
	std::cin >> a;
	a = 1000 - a;

	coin += a / 500;
	a = a - ((a / 500) * 500);
	coin += a / 100;
	a = a - ((a / 100) * 100);
	coin += a / 50;
	a = a - ((a / 50) * 50);
	coin += a / 10;
	a = a - ((a / 10) * 10);
	coin += a / 5;
	a = a - ((a / 5) * 5);
	coin += a / 1;
	a = a - ((a / 1) * 1);

	std::cout << coin;




}

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

int main(){
  int cost, count=0;
  cin>>cost;
  cost=1000-cost;
  while(cost>=500)count++,cost-=500;
  while(cost>=100)count++,cost-=100;
  while(cost>=50)count++,cost-=50;
  while(cost>=10)count++,cost-=10;
  while(cost>=5)count++,cost-=5;
  while(cost>=1)count++,cost-=1;
  cout<<count<<endl;
  return 0;
}

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

int nedan;
int oturi;
int maisuu = 0;
int i;
	

 int main(){
	cin >> oturi;
	i = 1000 - oturi;
	for(i=0 ; i<1000; )
	{
		if(nedan<500)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<100)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<50)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<10)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<5)maisuu+=1;
	}
	for(i=0 ; i<1000; ){
		if(nedan<1)maisuu+=1;
	}
	 return 0;
 }

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int m;
	while(cin>>m,m){
    	int c[]={1,5,10,50,100,500};
    	m=1000-m;
    	int ans=0;
    	for(int i=5;i>=0;i--){
    		ans+=m/c[i];
    		m%=c[i];
    	}
    	cout<<ans<<endl;
	}
}

C++: #include <iostream>

int main(){
    while(true){
        int N;
        std::cin >> N;
        
        if(N == 0){
            break;
        }
        
        N = 1000 - N;
        
        int count = 0;
        
        count += N / 500;
        N %= 500;
        count += N / 100;
        N %= 100;
        count += N / 50;
        N %= 50;
        count += N / 10;
        N %= 10;
        count += N / 5;
        N %= 5;
        count += N / 1;
        N %= 1;
        
        std::cout << count << std::endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0;

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	int j = (s - s % 500)/500;
        count += j;
	s -= j*500;
        j = (s - s % 100)/100;
        count += j;
	s -= j*100;
        j = (s - s % 100)/100;
        count += j;
	s -= j*50;
        j = (s - s % 50)/50;
        count += j;
	s -= j*10;
        j = (s - s % 10)/10;
        count += j;
	s -= j*10;
        j = (s - s % 5)/5;
        count += j;
	s -= j*5;
        count += s;

	cout << count << endl;
    }
    return 0;
}