<p>You are given a string of digits <code>num</code>, such as <code>&quot;123456579&quot;</code>. We can split it into a Fibonacci-like sequence <code>[123, 456, 579]</code>.</p>

<p>Formally, a <strong>Fibonacci-like</strong> sequence is a list <code>f</code> of non-negative integers such that:</p>

<ul>
	<li><code>0 &lt;= f[i] &lt; 2<sup>31</sup></code>, (that is, each integer fits in a <strong>32-bit</strong> signed integer type),</li>
	<li><code>f.length &gt;= 3</code>, and</li>
	<li><code>f[i] + f[i + 1] == f[i + 2]</code> for all <code>0 &lt;= i &lt; f.length - 2</code>.</li>
</ul>

<p>Note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number <code>0</code> itself.</p>

<p>Return any Fibonacci-like sequence split from <code>num</code>, or return <code>[]</code> if it cannot be done.</p>

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

<pre>
<strong>Input:</strong> num = &quot;1101111&quot;
<strong>Output:</strong> [11,0,11,11]
<strong>Explanation:</strong> The output [110, 1, 111] would also be accepted.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;112358130&quot;
<strong>Output:</strong> []
<strong>Explanation:</strong> The task is impossible.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;0123&quot;
<strong>Output:</strong> []
<strong>Explanation:</strong> Leading zeroes are not allowed, so &quot;01&quot;, &quot;2&quot;, &quot;3&quot; is not valid.
</pre>

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

<ul>
	<li><code>1 &lt;= num.length &lt;= 200</code></li>
	<li><code>num</code> contains only digits.</li>
</ul>

class Solution {
public:
    // # define int long long
    string func(string &num , int s ,int e){
        string res="";
        for(int i=s;i<=e;i++){res.push_back(num[i]);}
        return res;
    }

    bool cmp(string &s1 , string &s2){
        if(s1.size() < s2.size())return false;
        if(s1.size() > s2.size())return true;
        return s1>s2;
    }

    vector<int> splitIntoFibonacci(string s) {
        int m = INT_MAX;
        string atmax = to_string(m);

        for(int i=0;i<s.size();i++){
            string temp = func(s,0,i);
            if((temp.size()>1 && temp[0]=='0') || cmp(temp,atmax))break;

            for(int j=i+1;j<s.size() ; j++){
                string temp2 = func(s,i+1,j);
                if( (temp2.size()>1 && temp2[0]=='0') || cmp(temp,atmax))break;

                // cout<<temp<<' '<< temp2<<endl;
                long long a = stoll(temp);
                long long b = stoll(temp2);
                if(a> INT_MAX || b> INT_MAX)break;

                string x="";
                int k = j+1;
                vector<string> adx;
                while(k<s.size()){
                    x.push_back(s[k]);
                    if((x.size()>1 && x[0]=='0') || cmp(x,atmax))break;
                    // cout << x <<' ';

                    long long int c =  stoi(x);
                    if(c> INT_MAX)break;
                    if(k==s.size()-1){
                        if(c!=a+b){
                            k--;
                            break;
                        }
                    }
                    if(c==a+b){
                        a= b;
                        b= c;
                        adx.push_back(x);
                        x="";
                    }
                    k++;
                }
                
                // cout<<endl;
                // cout<< temp << ' '<< temp2 <<' ' ;
                // for(auto p:adx)cout<<p<<' ';cout<<endl;

                // cout<<endl<<endl;

                if(k==s.size() && adx.size()>0){
                    vector<int> res;
                    res.push_back(stoi(temp));
                    res.push_back(stoi(temp2));
                    for(auto p:adx){
                        res.push_back(stoi(p));
                    }
                    return res;
                }
                
                // cout<<temp<<' '<< temp2<<endl; 
            }

        }

        return {};

    }
};
9700