<s>[INST] I am looking for an algorithm to determine the longest increasing subsequence in an array of integers, but I only want to consider subsequence of length 3 or more. 

Here's my current attempt:

```python
def longest_increasing_subsequence(arr):
    n = len(arr)
    lis = [1] * n

    for i in range(1, n):
        for j in range(i):
            if arr[i] > arr[j]:
                lis[i] = max(lis[i], lis[j] + 1)

    max_lis = 0
    for i in range(n):
        max_lis = max(max_lis, lis[i])
        if lis[i] >= 3:
            if max_lis < lis[i]:
                max_lis = lis[i]

    return max_lis if max_lis >= 3 else -1
```

However, my code seems to be a bit of a mess. I have an additional loop at the end to find the maximum `lis` value that is 3 or more.

Is there a way to improve the algorithm and make the code cleaner?[/INST]