Write a program to merge two sorted linked lists, remove any duplicate elements, and return the sorted result.
Assume each list is represented by a ListNode with val and next, and return the head of a linked list containing each value once.
For example, [1, 2, 4] and [1, 3, 4] produce [1, 2, 3, 4]; inputs may be empty and contain negative or repeated values.
def merge_unique_lists(head1, head2):