#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[4];
int coin[]{500,100,50,10};
int main(){
	int n;scanf("%d",&n);
	while(1){
		rep(i,4)scanf("%d",&a[i]);
		scanf("%d",&n);
		rep(i,4){
			int cnt=0;
			while(n-coin[i]>=0){
				n-=coin[i];
				cnt++;
			}
			
		}
		if(n)printf("\n");
		else break;
	}
}