c=[]
ans=[]

3.times do
c.push gets.chomp

i=0
for i in 0..2

  if c[i]!=0

    s1=(1000-c[i])/500
    r1=(1000-c[i])%500
    s2=r1/100
    r2=r1%100
    s3=r2/50
    r3=r2%50
    s4=r3/10
    r4=r3%10
    s5=r4/5
    r5=r4%5

    ans.push s1+s2+s3+s4+s5+r5

    i=i+1

  else

    ans[i]="\n"
    
    i=i+1
end

puts ans