<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def merge(root, head, update, head_source=None):
 """ This function instantiate a ``Merger`` object using a configuration in according to the ``source`` value of head and update params. Then it run the merger on the three files provided in input. Params root(dict):
 the last common parent json of head and update head(dict):
 the last version of a record in INSPIRE update(dict):
 the update coming from outside INSPIRE to merge head_source(string):
 the source of the head record. If ``None``, heuristics are used to derive it from the metadata. This is useful if the HEAD came from legacy and the acquisition_source does not reflect the state of the record. Return A tuple containing the resulted merged record in json format and a an object containing all generated conflicts. """

    configuration = get_configuration(head, update, head_source)
    conflicts = []

    root, head, update = filter_records(root, head, update, filters=configuration.pre_filters)
    merger = Merger(
        root=root, head=head, update=update,
        default_dict_merge_op=configuration.default_dict_merge_op,
        default_list_merge_op=configuration.default_list_merge_op,
        list_dict_ops=configuration.list_dict_ops,
        list_merge_ops=configuration.list_merge_ops,
        comparators=configuration.comparators,
    )

    try:
        merger.merge()
    except MergeError as e:
        conflicts = e.content
    conflicts = filter_conflicts(conflicts, configuration.conflict_filters)
    conflicts_as_json = [json.loads(c.to_json()) for c in conflicts]
    flat_conflicts_as_json = list(itertools.chain.from_iterable(conflicts_as_json))

    merged = merger.merged_root
    return merged, flat_conflicts_as_json