CF1845B.Come Together

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 AA , BB , and CC respectively. Right now, all of them are in cell AA .

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 BB , Carol — to the cell CC . 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?

输入格式

The first line contains the single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains two integers xAx_A and yAy_A ( 1xA,yA1081 \le x_A, y_A \le 10^8 ) — the position of cell AA , where both Bob and Carol are right now.

The second line contains two integers xBx_B and yBy_B ( 1xB,yB1081 \le x_B, y_B \le 10^8 ) — the position of cell BB (Bob's house).

The third line contains two integers xCx_C and yCy_C ( 1xC,yC1081 \le x_C, y_C \le 10^8 ) — the position of cell CC (Carol's house).

Additional constraint on the input: the cells AA , BB , and CC are pairwise distinct in each test case.

输出格式

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.

输入输出样例

  • 输入#1

    3
    3 1
    1 3
    6 4
    5 2
    2 2
    7 2
    1 1
    4 3
    5 5

    输出#1

    3
    1
    6

说明/提示

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.

首页