:-use_module(library(clpfd)).


megoldas([S,E,N,D,M,O,R,Y]) :-
  domain([S,E,N,D,M,O,R,Y], 0, 9), 
  all_distinct([S,E,N,D,M,O,R,Y]), 
  M#>=1, 
  1000*(S+M)+100*(E+O)+10*(N+R)+D+E #= 10000*M+1000*O+100*N+10*E+Y, 
  labeling([ff],[S,E,N,D,M,O,R,Y]).