def merge(lists, optimize_for_speed=True):
    """ merge lists into one, while removing duplicates but keeping element order.
		`optimize_for_speed` is True has better runtime complexity
		`optimize_for_speed` is False uses less memory
	"""
    merged = []
    if optimize_for_speed:
        uniques = set()
        for list in lists:
            for element in list:
                if element not in uniques:
                    merged.append(element)
                    uniques.add(element)
    else:
        for list in lists:
            for element in list:
                if element not in merged:
                    merged.append(element)
    return merged
