def get_max_parsimony_n_alleles(n, ploidy):
    """Get the expected number of true alleles in the connected component
    given that n alleles have been observed.

    The returned value can be seen as the parsimonious solution: if ploidy is
    higher than the number of observed alleles, there must be at least as many
    alleles as the ploidy (though some are the same, e.g. at homozygous loci).
    If ploidy is less than the observed alleles, there must be so many additional
    alleles that are the same as one of the observed such that the number of alleles
    can be divided by the ploidy."""
    remainder = n % ploidy
    if ploidy >= n:
        return ploidy
    elif remainder:
        return n + ploidy - remainder
    else:
        return n