<p>A sequence <code>x<sub>1</sub>, x<sub>2</sub>, ..., x<sub>n</sub></code> is <em>Fibonacci-like</em> if:</p>

<ul>
	<li><code>n &gt;= 3</code></li>
	<li><code>x<sub>i</sub> + x<sub>i+1</sub> == x<sub>i+2</sub></code> for all <code>i + 2 &lt;= n</code></li>
</ul>

<p>Given a <b>strictly increasing</b> array <code>arr</code> of positive integers forming a sequence, return <em>the <strong>length</strong> of the longest Fibonacci-like subsequence of</em> <code>arr</code>. If one does not exist, return <code>0</code>.</p>

<p>A <strong>subsequence</strong> is derived from another sequence <code>arr</code> by deleting any number of elements (including none) from <code>arr</code>, without changing the order of the remaining elements. For example, <code>[3, 5, 8]</code> is a subsequence of <code>[3, 4, 5, 6, 7, 8]</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [1,2,3,4,5,6,7,8]
<strong>Output:</strong> 5
<strong>Explanation:</strong> The longest subsequence that is fibonacci-like: [1,2,3,5,8].</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr = [1,3,7,11,12,14,18]
<strong>Output:</strong> 3
<strong>Explanation</strong>:<strong> </strong>The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18].</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= arr.length &lt;= 1000</code></li>
	<li><code>1 &lt;= arr[i] &lt; arr[i + 1] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def lenLongestFibSubseq(self, arr: List[int]) -> int:
        max_length=0
        final_sol={}
        i=len(arr)-1
        while i>0:
            dict_sol={}
            dict_sol= self.twoSum(arr[0:i],arr[i])
            for key,value in dict_sol.items():
                value.append(arr[i])
            for key,value in dict_sol.items():
                first=value[0]
                low_index=key
                second=value[1]
                third=arr[i]
                while True:
                    x=-1
                    try:
                        x=arr[0:low_index+1].index(second-first)
                        print(x)
                    except:
                        print("Here's a solution!")
                        print(value)
                        final_sol[tuple(value)]=True
                        break
                    finally:
                        if x==low_index:
                            print("Here's a solution!")
                            print(value)
                            final_sol[tuple(value)]=True
                            break
                        dict_sol[key]=value.insert(0,second-first)
                        low_index=x
                        second=first
                        first=arr[low_index]
            i-=1
        print(final_sol)
        max_len=0
        for key in final_sol.keys():
            if len(key)>max_len:
                max_len=len(key)
            
        return max_len
                
                        





    def twoSum(self, nums2: List[int], target: int):
        dict2={}
        results={}
        for i in range(len(nums2)):
            if (nums2[i] in dict2):
                ind1=dict2[nums2[i]][1]
                ind2=i
                results[ind1]=[nums2[ind1],nums2[ind2]]

                
            else :
                x=target-nums2[i]
                dict2[x]=[nums2[i],i]
        return results
        
18200