Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

C++: #include <iostream>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

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

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

int main()
{
	//?????????
	int num1=0,num2=0,num3=0;
	int p1=0,p2=0,p3=0,p4=0,p5=0,p6=0;
	int u1=0,u2=0,u3=0,u4=0,u5=0,u6=0;
	
	cin>>num1;
	if(num1<1||1000<=num1){
		return 0;
	}
	num2=1000-num1;
	p1=num2/500;
	u1=num2%500;
	p2=u1/100;
	u2=u1%100;
	p3=u2/50;
	u3=u2%50;
	p4=u3/10;
	u4=u3%10;
	p5=u4/5;
	u5=u4%5;
	p6=u5/1;
	u6=u5%1;
	num3=p1+p2+p3+p4+p5+p6;
	cout<<num3;
	cout<<"\n";
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt=0,div[6]=[500,100,50,10,5,1]i;
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;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int n;

int main() {

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

	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[6], count=0, coin[] = { 500,100,50,10,5 };

    for (int i=0; i<6; i++) 
{
cin >> n[i];
if(!n[i])break;
}

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

	int s=1000 - n[i];

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << endl;
count = 0;
    }
    return 0;
}

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

C++: #include <iostream>
#include <algorithm>
#include <array>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(),x.end())

using int64 = uint64_t;

using namespace std;
void solve(int x) {
	x = 1000 - x;
	int cnt = 0;
	int a[6] = { 500,100,50,10,5,1 };
	rep(i,0,6){
		while (x >= a[i]) {
			x -= a[i];
			cnt++;
		}
	}
	cout << cnt << endl;
}
int main() {

	int i, j, k;
	int n;
	cin >> n;
	while (n != 0) {
		solve(n);
		cin >> n;
	}
	return 0;
}

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

int main()
{
while(true) {
int n;
scanf("%d", &n);
if(n == 0)
break;
int change = 1000 - n;
int ans = 0;
for(int digit = 1; digit < 1000; mul *= 10) {
int cur = change / digit % 10;
ans += (cur / 5) + (cur % 5);
}
printf("%d\n", ans);
}
return 0;
}

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

int money,c[1010],n,x;
int main(){
  x=0;
  scanf("%d",&money);
  n=1000-money;
  for(int i=0;500<=n;i++){x++;n=n-500;}
  for(int i=0;100<=n;i++){x++;n=n-100;}
  for(int i=0;50<=n;i++){x++;n=n-50;}
  for(int i=0;10<=n;i++){x++;n=n-10;}
  for(int i=0;5<=n;i++){x++;n=n-5;}
  for(int i=0;1<=n;i++){x++;n=n-1;}
  printf("%d",x);
}

C++: // quest1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	int money, reverse, count = 0;

	scanf("%d", &money);
	reverse = 1000 - money;

	while (reverse >= 500) {
		reverse -= 500;
		count++;
	}
	while (reverse >= 100) {
		reverse -= 100;
		count++;
	}
	while (reverse >= 50) {
		reverse -= 50;
		count++;
	}
	while (reverse >= 10) {
		reverse -= 10;
		count++;
	}
	while (reverse >= 5) {
		reverse -= 5;
		count++;
	}
	while (reverse >= 1) {
		reverse -= 1;
		count++;
	}

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

int main(){
    
    
    while(true){
    int n;
    cin>>n;
        
        if(n==0)break;
    
    int t=1000-n;
    int ans=0;
    
    ans+=t/500;
    t=t%500;
    
    ans+=t/100;
    t=t%100;
    
    ans+=t/50;
    t=t%50;
    
    ans+=t/10;
    t=t%10;
    
    ans+=t/5;
    t=t%5;
    
    ans+=t;
    
    cout<<ans<<endl;
    }
    
    return 0;
    
}

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

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum[5];
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum[i]++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum[i]++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum[i]++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum[i]++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum[i]++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum[i]++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum[0] << endl;
	cout << onum[1] << endl;
	cout << onum[2] << endl;
	cout << onum[3] << endl;
	cout << onum[4] << endl;
	return 0;
}