% https://open.kattis.com/problems/baconeggsandspam % 1s % 1.8 Easy % Picat, using maps (and some function stuff) import util. main :- S = read_file_lines(), s(S). s([]). s(["0"]). s([S|Ss]) :- L = new_list(S.to_int), append(L,Ss2,Ss), Food = new_map(), foreach(T in L, [P|Fs]=T.split) foreach(F in Fs) Food.put(F,Food.get(F,[])++[P]) end end, foreach(F in Food.keys.sort) printf("%s %s\n",F,Food.get(F).sort.join(" ")) end, nl, s(Ss2).