def merge(*args, **kwargs):
    """
    Merges several dictionaries. Checks for consistent values.

    :param args: dictionaries
    :return: merged dict
    """
    ret = dict(args[0])
    for d in args[1:] + (kwargs,):
        for k in d:
            if k in ret:
                if d[k] != ret[k]:
                    raise ValueError('Inconsistent values for key', k)
            else:
                ret[k] = d[k]
    return ret