------
## 最终结论
```python
def maxSumDivThree(nums):
    sum_total = sum(nums)
    remainder = sum_total % 3
    
    if remainder == 0:
        return sum_total
    
    # Create lists to hold numbers based on their mod 3 value
    mod1 = []
    mod2 = []
    
    for num in nums:
        if num % 3 == 1:
            mod1.append(num)
        elif num % 3 == 2:
            mod2.append(num)
    
    # Sort the lists to find the smallest elements
    mod1.sort()
    mod2.sort()
    
    if remainder == 1:
        option1 = mod1[0] if mod1 else float('inf')
        option2 = (mod2[0] + mod2[1]) if len(mod2) > 1 else float('inf')
        min_remove = min(option1, option2)
        
    else: # remainder == 2
        option1 = mod2[0] if mod2 else float('inf')
        option2 = (mod1[0] + mod1[1]) if len(mod1) > 1 else float('inf')
        min_remove = min(option1, option2)
    
    return sum_total - min_remove

# Example usage
nums = [3, 6, 5, 1, 8]
print(maxSumDivThree(nums))  # Output: 18

nums = [4]
print(maxSumDivThree(nums))  # Output: 0

nums = [1, 2, 3, 4, 4]
print(maxSumDivThree(nums))  # Output: 12
```