s(N,LX,LY,LV):-
	NN is N*N,
	NN1 is NN-1,
	fd_set_vector_max(NN1),
	length(LX,NN),
	length(LY,NN),
	N1 is N-1,
	fd_domain(LX,0,N1),
	fd_domain(LY,0,N1),
	LX=[X|LX1],
	LY=[Y|LY1],
	cstr1(LX,LY,N,LV),
	fd_all_different(LV),
	cstr2(LX1,X,LY1,Y).



cstr1([],[],_,[]).

cstr1([X|LX],[Y|LY],N,[V|LV]):-
	V #= N*X+Y,
	cstr1(LX,LY,N,LV).


cstr2([],_,[],_).

cstr2([Xj|LX],Xi,[Yj|LY],Yi):-
	fd_domain([DX,DY],1,2),
	DX#=absd(Xi,Xj),
	DY#=absd(Yi,Yj),
	DX+DY#=3,
	cstr2(LX,Xj,LY,Yj).



s(N,LV,Opt):- s(N,_LX,_LY,LV),  fd_labeling(LV,Opt).

s1(N,LV,Opt):- s(N,LX,LY,LV),  lb(LX,LY,Opt).

lb([],[],_).

lb([X|LX],[Y|LY],Opt):-
	fd_labeling(X,Opt),
	fd_labeling(Y,Opt),
	lb(LX,LY,Opt).
