def infra(starting, tobuy):
    """Calculates the cost of infra from a given amount to an ending amount."""
    tobuy = tobuy - starting
    if -1 < starting < 10000 and -1 < tobuy < 10000:
        if tobuy > 100:
            count = 0
            cost = 0
            r = tobuy / 100 + 1.0
            for _ in range(int(r)):
                factor = starting + count
                count = count + 100
                if tobuy >= 100:
                    buying = 100
                    tobuy -= 100
                else:
                    buying = tobuy
                cost = cost + ((factor - 10) ** 2.2 / 710 + 300) * buying
        else:
            cost = ((starting - 10) ** 2.2 / 710 + 300) * tobuy
        return cost
    raise ValueError(
        'You passed invalid values! They need to be between 0 and 10000')
