def h(sample):
    """Cost function that applies to a single sample and gets lower if there are photons in odd
    numbered modes and higher with photons in even numbered modes. The higher-numbered modes have a
    greater effect due to the (i + 1) term."""
    return -sum([s * (i + 1) * (-1) ** (i + 1) for i, s in enumerate(sample)])