------
## 最终结论
```python
def rob(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    def rob_linear(houses):
        prev, curr = 0, 0
        for money in houses:
            prev, curr = curr, max(curr, prev + money)
        return curr

    # Since the houses are in a circle, we have two cases:
    # 1. Exclude the first house and include the last house.
    # 2. Include the first house and exclude the last house.
    return max(rob_linear(nums[:-1]), rob_linear(nums[1:]))

# Example usage:
# print(rob([2,3,2])) # Output: 3
# print(rob([1,2,3,1])) # Output: 4
```