A:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
/**
* @author:Skyme
* @create: 2023-08-13 13:37
* @Description:
*/
public class A {
static int n;
static int x[];
static int y[];
static int z[];
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
// static public int search(int[] num){
// int l=0;
// int r=num.length-1;
// while (l<=r){
//
// }
// }
public static void main(String[] args) throws IOException {
//按样例来看,就是找出每个的中间值
//先排序后二分即可
n=Integer.parseInt(br.readLine());
x=new int[n];
y=new int[n];
z=new int[n];
for(int i=0;i<n;i++){
String[] s = br.readLine().split(" ");
x[i]=Integer.parseInt(s[0]);
y[i]=Integer.parseInt(s[1]);
z[i]=Integer.parseInt(s[2]);
}
Arrays.sort(x);
Arrays.sort(y);
Arrays.sort(z);
int mid=n/2;
long cnt = 0;
for(int i=0;i<n;i++){
cnt+=Math.abs(x[i]-x[mid]);
}
int index=0;
//要构造成队列
//那么第一个数就要加上mid在当前队列的位置与第一个位置的差值
//mid+1->第x个数
//
for(int i=0;i<n;i++){
cnt+=Math.abs(y[i]-y[mid])-Math.abs((mid+1)-(i+1));
}
for(int i=0;i<n;i++){
cnt+=Math.abs(z[i]-z[mid]);
}
if(n%2==0){
}else {
}
System.out.println(cnt);
//7 8 9 10 /4 2 0 2/ 6 3 0 3/ 8 12
//越靠近中心的那个数就减去中心差值
}
}
2023/8/13大约 8 分钟
