x(X):-current_input(I),read_string(I,' \n','',_,X).
n(N):-x(X),number_string(N,X).
s(V,0):- writeln(V),!.
s(V,N):- 0 is N mod 3,N1 is N-1,s(V,N1).
s(V,N):- 0 is N mod 5,N1 is N-1,s(V,N1).
s(V,N):- V1 is V+N,N1 is N-1,s(V1,N1).
main:- n(N),s(0,N).
