<p>Given two arrays of integers with equal lengths, return the maximum value of:</p>

<p><code>|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|</code></p>

<p>where the maximum is taken over all <code>0 &lt;= i, j &lt; arr1.length</code>.</p>

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

<pre>
<strong>Input:</strong> arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
<strong>Output:</strong> 13
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
<strong>Output:</strong> 20
</pre>

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

<ul>
	<li><code>2 &lt;= arr1.length == arr2.length &lt;= 40000</code></li>
	<li><code>-10^6 &lt;= arr1[i], arr2[i] &lt;= 10^6</code></li>
</ul>

class Solution {
    int dif(vector<int> a, int n){
        int mn= a[0], mx=a[0];
        for(int i = 0; i < n; i++){
            mn = min(a[i],mn);
            mx=max(a[i], mx);
        }
        return mx-mn;
    }
public:
    int maxAbsValExpr(vector<int>& a, vector<int>& b) {
       int n = a.size();
       vector<int> s1(n,0),d1(n,0),s2(n,0),d2(n,0);
        for(int i=0;i<n;i++) {
            s1[i]=a[i]+b[i]+i;
            d1[i]=a[i]-b[i]+i;
            s2[i]=a[i]+b[i]-i;
            d2[i]=a[i]-b[i]-i;
        }
        int res=0;
        res=max(res, dif(s1,n));
        res = max(res,dif(d1,n));
        res = max(res,dif(s2,n));
        res = max(res,dif(d2,n));
        return res;
    }
    
};
30800