Download
top:-
	utime(_),
	L = [
	V000,V001,V002,V003,V004,V005,V006,V007,V008,V009,
	V010,V011,V012,V013,V014,V015,V016,V017,V018,V019,
	V020,V021,V022,V023,V024,V025,V026,V027,V028,V029,
	V030,V031,V032,V033,V034,V035,V036,V037,V038,V039,
	V040,V041,V042,V043,V044,V045,V046,V047,V048,V049,
	V050,V051,V052,V053,V054,V055,V056,V057,V058,V059,
	V060,V061,V062,V063,V064,V065,V066,V067,V068,V069,
	V070,V071,V072,V073,V074,V075,V076,V077,V078,V079,
	V080,V081,V082,V083,V084,V085,V086,V087,V088,V089,
	V090,V091,V092,V093,V094,V095,V096,V097,V098,V099,
	V100,V101,V102,V103,V104,V105,V106,V107,V108,V109,
	V110,V111,V112,V113,V114,V115,V116,V117,V118,V119,
	V120,V121,V122,V123,V124,V125,V126,V127,V128,V129,
	V130,V131,V132,V133,V134,V135,V136,V137,V138,V139
	],
	L :: 1..40,

	length(Null,140),
	Null :: 0..0,
	Values = [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],
		  [11],[12],[13],[14],[15],[16],[17],[18],[19],[20],
		  [21],[22],[23],[24],[25],[26],[27],[28],[29],[30],
		  [31],[32],[33],[34],[35],[36],[37],[38],[39],[40]],
	length(Null4,4),
	Null4 :: 0..0,
	Values4 = [[1,2,3,4,5,6,7,8,9,10],
		   [11,12,13,14,15,16,17,18,19,20],
		   [21,22,23,24,25,26,27,28,29,30],
		   [31,32,33,34,35,36,37,38,39,40]],

	E = ground,

	Repeat = [3,3,3,3,3,4,4,4,4,4,
		  3,3,3,3,3,4,4,4,4,4,
		  3,3,3,3,3,4,4,4,4,4,
		  3,3,3,3,3,4,4,4,4,4],

	mult_among(Repeat,L,Null,Values,E),

	differ([V000,V004,V008,V012,V016,V020,V024,V028,
		      V032,V036,V040,V044,V048,V052,V056,V060,
		      V064,V068,V072,V076,V080,V084,V088,V092,
		      V096,V100,V104,V108,V112,V116,V120,V124,
		      V128,V132,V136]),

	differ([V003,V007,V011,V015,V019,V023,V027,V031,
		      V035,V039,V043,V047,V051,V055,V059,V063,
		      V067,V071,V075,V079,V083,V087,V091,V095,
		      V099,V103,V107,V111,V115,V119,V123,V127,
		      V131,V135,V139]),
	differ([V002,V006,V010,V014,V018,V022,V026,V030,
		      V034,V038,V042,V046,V050,V054,V058,V062,
		      V066,V070,V074,V078,V082,V086,V090,V094,
		      V098,V102,V106,V110,V114,V118,V122,V126,
		      V130,V134,V138]),

	differ([V001,V005,V009,V013,V017,V021,V025,V029,
		      V033,V037,V041,V045,V049,V053,V057,V061,
		      V065,V069,V073,V077,V081,V085,V089,V093,
		      V097,V101,V105,V109,V113,V117,V121,V125,
		      V129,V133,V137]),

	differ([V000,V001,V002,V003,V004,V005,V006,V007,V008,V009,
	V010,V011,V012,V013,V014,V015,V016,V017,V018,V019,
	V020,V021,V022,V023,V024,V025,V026,V027,V028,V029,
	V030,V031,V032,V033,V034,V035,V036,V037,V038,V039]),

	differ([V040,V041,V042,V043,V044,V045,V046,V047,V048,V049,
	V050,V051,V052,V053,V054,V055,V056,V057,V058,V059,
	V060,V061,V062,V063,V064,V065,V066,V067]),

	differ([V068,V069,
	V070,V071,V072,V073,V074,V075,V076,V077,V078,V079,
	V080,V081,V082,V083,V084,V085,V086,V087,V088,V089,
	V090,V091,V092,V093,V094,V095,V096,V097,V098,V099]),

	differ([V100,V101,V102,V103,V104,V105,V106,V107,V108,V109,
	V110,V111,V112,V113,V114,V115,V116,V117,V118,V119,
	V120,V121,V122,V123,V124,V125,V126,V127,V128,V129,
	V130,V131,V132,V133,V134,V135,V136,V137,V138,V139]),

	distri([V000,V001,V002,V003],Null4,Values4,E),
	distri([V004,V005,V006,V007],Null4,Values4,E),
	distri([V008,V009,V010,V011],Null4,Values4,E),
	distri([V012,V013,V014,V015],Null4,Values4,E),
	distri([V016,V017,V018,V019],Null4,Values4,E),
	distri([V020,V021,V022,V023],Null4,Values4,E),
	distri([V024,V025,V026,V027],Null4,Values4,E),
	distri([V028,V029,V030,V031],Null4,Values4,E),
	distri([V032,V033,V034,V035],Null4,Values4,E),
	distri([V036,V037,V038,V039],Null4,Values4,E),
	distri([V040,V041,V042,V043],Null4,Values4,E),
	distri([V044,V045,V046,V047],Null4,Values4,E),
	distri([V048,V049,V050,V051],Null4,Values4,E),
	distri([V052,V053,V054,V055],Null4,Values4,E),
	distri([V056,V057,V058,V059],Null4,Values4,E),
	distri([V060,V061,V062,V063],Null4,Values4,E),
	distri([V064,V065,V066,V067],Null4,Values4,E),
	distri([V068,V069,V070,V071],Null4,Values4,E),
	distri([V072,V073,V074,V075],Null4,Values4,E),
	distri([V076,V077,V078,V079],Null4,Values4,E),
	distri([V080,V081,V082,V083],Null4,Values4,E),
	distri([V084,V085,V086,V087],Null4,Values4,E),
	distri([V088,V089,V090,V091],Null4,Values4,E),
	distri([V092,V093,V094,V095],Null4,Values4,E),
	distri([V096,V097,V098,V099],Null4,Values4,E),
	distri([V100,V101,V102,V103],Null4,Values4,E),
	distri([V104,V105,V106,V107],Null4,Values4,E),
	distri([V108,V109,V110,V111],Null4,Values4,E),
	distri([V112,V113,V114,V115],Null4,Values4,E),
	distri([V116,V117,V118,V119],Null4,Values4,E),
	distri([V120,V121,V122,V123],Null4,Values4,E),
	distri([V124,V125,V126,V127],Null4,Values4,E),
	distri([V128,V129,V130,V131],Null4,Values4,E),
	distri([V132,V133,V134,V135],Null4,Values4,E),
	distri([V136,V137,V138,V139],Null4,Values4,E),

	labeling(L,0,most_constrained,my_indomain),
	writeln_time,
	writeln(L).

differ(S):-
	alldifferent(S).

mult_among([],L,Null,[],E).
mult_among([Repeat|R1],L,Null,[Values|V1],E):-
	among(Repeat,L,Null,Values,E),
	mult_among(R1,L,Null,V1,E).

distri(X,Y,V,E):-
	length(C,4),
	C :: 0..1,
	among(C,X,Y,V,E).

my_indomain(X):- % first try the values which can occur 4 times
	member(X,[6,7,8,9,10,16,17,18,19,20,26,27,28,29,30,36,37,38,39,40]).
my_indomain(X):- % then try the ones which can occur only 3 times
	member(X,[1,2,3,4,5,11,12,13,14,15,21,22,23,24,25,31,32,33,34,35]).