from structures import ListNode, build_list

def copy_random_list(head):
    clones = {}
    current = head
    while current is not None:
        clones[current] = ListNode(current.val)
        current = current.next
    current = head
    while current is not None:
        clones[current].next = clones.get(current.next)
        clones[current].random = clones.get(current.random)
        current = current.next
    return clones.get(head)
