:- prompt(_, '').
:- use_module(library(readutil)).
read_num(N):-read_string(user_input, "\n", " ", _, Str),number_string(N,Str).
read_list(Ys):-read_string(user_input, "\n", " ", _, Str),
split_string(Str, " ", "", Xs),
maplist(string_number,Xs,Ys).
string_number(Str,N):-number_string(N,Str).
seed(N,M,M2,_):-N<M2,!,false.
seed
(N
,M
,M2
,[M3
,E
]):-MD
is M
-1,between
(1,MD
,E
),M3
is M2
*E
.seed
(N
,M
,M2
,Res
):-M2a
is M2
*M
,seed
(N
,M
,M2a
,Res
).
seed2(N,E):-member(M,[6,9]),seed(N,M,M,E).
calc(Memo,[E0,C0],[N2,C2]):-member([N,C],Memo),
member([D1,D2],[[0,0],[E0,C0]]),
D1=<N,
dp2(N,C,[],[[N,C]]):-!.
dp2(N,C,[[N,_]|Memo],Res):-!,dp2(N,C,Memo,Res).
dp2(N,C,[[N2,C2]|Memo],[[N,C]|Res]):-dp2(N2,C2,Memo,Res).
dp(Memo,[],Memo):-!.
dp(Memo,[E|Seeds],Res):-!,
sort(Memo2,Memo3),
[[N,C]|_]=Memo3,
dp2(N,C,Memo3,Memo4),
sort(Memo4,Memo5),
dp(Memo5,Seeds,Res).
calc2([],[]):-!.
calc2
([[N
,C
]|Memo
],[R
|Res
]):-R
is N
+C
,calc2
(Memo
,Res
).
main:-
process,
process:-
/* your code goes here */
read_num(N),
sort(Seeds,Seeds2),
dp([[N,0]],Seeds2,Res),
calc2(Res,Ans),
sort(Ans,[Ans2|_]),
:- main.
Oi0gc2V0X3Byb2xvZ19mbGFnKHZlcmJvc2Usc2lsZW50KS4KOi0gcHJvbXB0KF8sICcnKS4KOi0gdXNlX21vZHVsZShsaWJyYXJ5KHJlYWR1dGlsKSkuCnJlYWRfbnVtKE4pOi1yZWFkX3N0cmluZyh1c2VyX2lucHV0LCAiXG4iLCAiICIsIF8sIFN0ciksbnVtYmVyX3N0cmluZyhOLFN0cikuCnJlYWRfbGlzdChZcyk6LXJlYWRfc3RyaW5nKHVzZXJfaW5wd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