https://www.acmicpc.net/problem/5585
// 거스름돈
int solution(int n){
int answer = 0;
int charge = 1000 - n;
int c[] = {500, 100, 50, 10, 5, 1};
for(int i=0;i<6;i++){
answer += charge/c[i];
charge = charge%c[i];
if(charge == 0)
break;
}
return answer;
}
int main(){
int n;
scanf("%d",&n),n=1000-n;
printf("%d",n/500+(n%500)/100+(n%100)/50+(n%50)/10+(n%10)/5+n%5);
return 0;
}