<p>You are given two integer arrays of the same length <code>nums1</code> and <code>nums2</code>. In one operation, you are allowed to swap <code>nums1[i]</code> with <code>nums2[i]</code>.</p>

<ul>
	<li>For example, if <code>nums1 = [1,2,3,<u>8</u>]</code>, and <code>nums2 = [5,6,7,<u>4</u>]</code>, you can swap the element at <code>i = 3</code> to obtain <code>nums1 = [1,2,3,4]</code> and <code>nums2 = [5,6,7,8]</code>.</li>
</ul>

<p>Return <em>the minimum number of needed operations to make </em><code>nums1</code><em> and </em><code>nums2</code><em> <strong>strictly increasing</strong></em>. The test cases are generated so that the given input always makes it possible.</p>

<p>An array <code>arr</code> is <strong>strictly increasing</strong> if and only if <code>arr[0] &lt; arr[1] &lt; arr[2] &lt; ... &lt; arr[arr.length - 1]</code>.</p>

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

<pre>
<strong>Input:</strong> nums1 = [1,3,5,4], nums2 = [1,2,3,7]
<strong>Output:</strong> 1
<strong>Explanation:</strong> 
Swap nums1[3] and nums2[3]. Then the sequences are:
nums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]
which are both strictly increasing.
</pre>

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

<pre>
<strong>Input:</strong> nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]
<strong>Output:</strong> 1
</pre>

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

<ul>
	<li><code>2 &lt;= nums1.length &lt;= 10<sup>5</sup></code></li>
	<li><code>nums2.length == nums1.length</code></li>
	<li><code>0 &lt;= nums1[i], nums2[i] &lt;= 2 * 10<sup>5</sup></code></li>
</ul>

class Solution {
public:
    //int minSwap(vector<int>& nums1, vector<int>& nums2) {
/*int print0(vector<int> b,vector<int> c,int e,int temp0){
   if(e==b.size()){
    return 0;
   }
   int temp2=0;
   int temp12=INT_MAX;
   int temp18=INT_MAX;
   if(e==0){
    temp12=print0(b,c,e+1,temp0);
    temp18=print0(b,c,e+1,1);
    if(temp18!=INT_MAX){
        temp18=temp18+1;
    }
    temp2=min(temp12,temp18);
   }
   else if(e!=0){
    if(temp0==0){
      if(b[e]>b[e-1] && c[e]>c[e-1]){
        temp12=print0(b,c,e+1,0);
      }  
      if(b[e]>c[e-1] && c[e]>b[e-1]){
        temp18=print0(b,c,e+1,1);
        if(temp18!=INT_MAX){
            temp18=temp18+1;
        }
      }
      temp2=min(temp12,temp18);
    }
    else if(temp0==1){
        if(b[e]>c[e-1] && c[e]>b[e-1]){
            temp12=print0(b,c,e+1,0);
        }
        if(b[e]>b[e-1] && c[e]>c[e-1]){
            temp18=print0(b,c,e+1,1);
            if(temp18!=INT_MAX){
                temp18=temp18+1;
            }
        }
        temp2=min(temp12,temp18);
    }
   }
   return temp2;
}
int minSwap(vector<int> b,vector<int> c){
    int e=0;
    int temp0=0;
    int temp2=0;
    int temp12=0;
    temp12=print0(b,c,temp0,temp2);
    return temp12;
    }*/
    int print0(vector<int> &b,vector<int> &c,vector<pair<pair<int,int>,pair<int,int>>> &e,int temp0,int temp2){
    if(temp0==b.size()){
        return 0;
    }
    int temp12=0;
    int temp18=INT_MAX;
    int temp28=INT_MAX;
    if(temp2==0){
        if(e[temp0].first.first!=-1 &&e[temp0].first.second!=-1){
            return min(e[temp0].first.first,e[temp0].first.second);
        }
    }
    if(temp2==1){
        if(e[temp0].second.first!=-1 && e[temp0].second.second!=-1){
            return min(e[temp0].second.first,e[temp0].second.second);
        }
    }
    if(temp0==0){
        temp18=print0(b,c,e,temp0+1,temp2);
        temp28=print0(b,c,e,temp0+1,1);
        e[temp0].first.first=temp18;
        //e[temp0].first.second=temp28;
        if(temp28!=INT_MAX){
            temp28=temp28+1;
        }
        e[temp0].first.second=temp28;
        temp12=min(temp18,temp28);
    }
    else if(temp0!=0){
        if(temp2==0){
            if(b[temp0]>b[temp0-1] && c[temp0]>c[temp0-1]){
                temp18=print0(b,c,e,temp0+1,temp2);
                e[temp0].first.first=temp18;
            }
            if(c[temp0]>b[temp0-1] && b[temp0]>c[temp0-1]){
                temp28=print0(b,c,e,temp0+1,1);
                if(temp28!=INT_MAX){
                    temp28=temp28+1;
                }
                e[temp0].first.second=temp28;
            }
            //e[tem]
            temp12=min(temp18,temp28);
        }
        else if(temp2==1){
                if(b[temp0]>c[temp0-1] && c[temp0]>b[temp0-1]){
                    temp18=print0(b,c,e,temp0+1,0);
                    e[temp0].second.first=temp18;
                }
                if(b[temp0]>b[temp0-1] && c[temp0]>c[temp0-1]){
                    temp28=print0(b,c,e,temp0+1,temp2);
                    if(temp28!=INT_MAX){
                        temp28=temp28+1;
                    }
                    e[temp0].second.second=temp28;
                }
                temp12=min(temp18,temp28);
        }
    }
    return temp12;
}
int minSwap(vector<int> b,vector<int> c){
    vector<pair<pair<int,int>,pair<int,int>>> e;
    for(int temp0=0;temp0<b.size();temp0++){
        pair<pair<int,int>,pair<int,int>> temp2;
        temp2.first.first=-1;
        temp2.first.second=-1;
        temp2.second.first=-1;
        temp2.second.second=-1;
        e.push_back(temp2);
    }
    int temp0=0;
    int temp2=0;
    int temp12=0;
    int temp18=0;
    temp18=print0(b,c,e,temp2,temp12);
    return temp18;
}
};
121861