/*
Can anyone tell me what's wrong in the following code. It is repeatedly getting "Wrong answer on test 4".
*/
#include<iostream>
#include<cmath>
using namespace std;
long long max(long long x, long long y)
{
if(x>y)
return x;
return y;
}
long long min(long long x, long long y)
{
if(x<y)
return x;
return y;
}
int main()
{
long long t,n,m,x1,y1,x2,y2,p,q,r,s;
cin >> t;
while(t--)
{
cin >> n >> m >> p >> q >> r >> s;
x1=y1=1;
x2=fabs(p-r)+1;
y2=fabs(q-s)+1;
if(x2==n && y2==m)
{
cout << m*n-2 << endl;
continue;
}
long long rbound=n-fabs(x2-x1);
long long bbound=m-fabs(y2-y1);
long long maxx=max(x1,x2);
long long maxy=max(y1,y2);
long long over=(rbound-maxx+1)*(bbound-maxy+1);
long long count=(rbound*2)*bbound;
long long tot=count-over;
cout << (m*n)-tot << endl;
}
return 0;
}
Consider copy-pasting some accepted solution and comparing outputs on a random set of tests.