------
## 最终结论
```python
def lenLongestFibSubseq(A):
    dp = {}
    n = len(A)
    index = {A[i]: i for i in range(n)}

    for j in range(n):
        for i in range(j):
            k = A[j] - A[i]
            if k in index and k < A[i]:  # Ensure k is a valid preceding element
                dp[(i, j)] = dp.get((index[k], i), 2) + 1

    max_length = 0
    for length in dp.values():
        max_length = max(max_length, length)

    return max_length if max_length >= 3 else 0

# Example usage:
print(lenLongestFibSubseq([1,2,3,4,5,6,7,8]))  # Output: 5
print(lenLongestFibSubseq([1,3,7,11,12,14,18]))  # Output: 3
```