let filter_both l = let add (h_acc, g_acc) (goal, p) = p::h_acc, if goal then p::g_acc else g_acc in List.fold_left add ([], []) l