Greedy Algorithms - Candy Distribution
Examine the following candy distribution code snippet. Which line contains a subtle bug that can cause incorrect candy assignments?
```python
def candy(ratings):
n = len(ratings)
candies = [1] * n
for i in range(1, n):
if ratings[i] > ratings[i - 1]:
candies[i] = candies[i - 1] + 1
for i in range(n - 2, -1, -1):
if ratings[i] > ratings[i + 1]:
candies[i] = candies[i + 1] + 1
return sum(candies)
```
