```python
def tier_cost(units: int, allowance: int, first_rate: int,    if units < 0:
        raise ValueError("Number of units cannot be less than zero")
    
    if units <= allowance:
        return units * first_rate
    
    return allowance * first_rate + (units -allowance) * later_rate
```