Come Together

发布时间 2023-07-12 16:04:07作者: o-Sakurajimamai-o
Come Together
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob and Carol hanged out with Alice the whole day, but now it's time to go home. Alice, Bob and Carol live on an infinite 2D grid in cells AB, and C respectively. Right now, all of them are in cell A.

If Bob (or Carol) is in some cell, he (she) can move to one of the neighboring cells. Two cells are called neighboring if they share a side. For example, the cell (3,5)(3,5) has four neighboring cells: (2,5)(2,5), (4,5)(4,5), (3,6)(3,6) and (3,4)(3,4).

Bob wants to return to the cell B, Carol — to the cell C. Both of them want to go along the shortest path, i. e. along the path that consists of the minimum possible number of cells. But they would like to walk together as well.

What is the maximum possible number of cells that Bob and Carol can walk together if each of them walks home using one of the shortest paths?

Input

The first line contains the single integer t (1t1041≤≤104) — the number of test cases.

The first line of each test case contains two integers xA and yA (1xA,yA1081≤,≤108) — the position of cell A, where both Bob and Carol are right now.

The second line contains two integers xB and yB (1xB,yB1081≤,≤108) — the position of cell B (Bob's house).

The third line contains two integers xC and yC (1xC,yC1081≤,≤108) — the position of cell C (Carol's house).

Additional constraint on the input: the cells AB, and C are pairwise distinct in each test case.

Output

For each test case, print the single integer — the maximum number of cells Bob and Carol can walk together if each of them goes home along one of the shortest paths.

Example
input
Copy
3
3 1
1 3
6 4
5 2
2 2
7 2
1 1
4 3
5 5
output
Copy
3
1
6
Note

In all pictures, red color denotes cells belonging only to Bob's path, light blue color — cells belonging only to Carol's path, and dark blue color — cells belonging to both paths.

One of the optimal routes for the first test case is shown below:

Bob's route contains 55 cells, Carol's route — 77 cells, and they will visit 33 cells together.

The optimal answer for the second test case is shown below:

 

Bob's route contains 44 cells, Carol's route — 33 cells, and they will visit only 11 cell together.

One of the optimal answers for the third test case is shown below:

Bob's route contains 66 cells, Carol's route — 99 cells, and they will visit 66 cells together.
//Come Together
//将x,y分开看
//如果a在b和c的中间的话,那么他俩肯定要分开走的,所以默认是1
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10,mod=1e9+7;
string s;
int n,t,a[N],f[N],res,num,ans,m;
bool vis[N];
signed main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        int xa,ya,xb,yb,xc,yc;
        cin>>xa>>ya>>xb>>yb>>xc>>yc;
        int x1=xa-xb,x2=xa-xc,y1=ya-yb,y2=ya-yc,res=1;
        if(x1<0&&x2<0||x1>0&&x2>0) res+=min(abs(x1),abs(x2));//都在左侧或者都在右侧
        if(y1<0&&y2<0||y1>0&&y2>0) res+=min(abs(y1),abs(y2));//都在上侧或者都在下侧
        cout<<res<<endl;
    }
    return 0;
}