def n50(lengths, genome_size=None):
    """
	Return N50 or NG50 value given a list of lengths.

	If the genome_size is not given, it is set to sum(lengths). The resulting
	value is the N50. If it is given, the resulting value is the NG50.

	If genome_size is greater than 2 * sum(lengths), None is returned.
	"""
    if genome_size is None:
        genome_size = sum(lengths)
    lengths = sorted(lengths, reverse=True)
    running_total = 0
    for length in lengths:
        running_total += length
        if running_total >= genome_size * 0.5:
            return length
    return None
