v=[500,100,50,10,5,1] c=[*map(int,input().split())] for i in range(len(v)): #print((c[i]+1)*v[i]) print(c[-1]) if c[-1]<=(c[i]+1)*v[i]: c[-1]-=(c[-1]//v[i])*v[i] print(c[-1]) print('YES' if c[-1]==0 else 'NO')