Space is represented as a -dimensional
cube where each coordinate is between
and
, and is a dangerous place. You are riding a spaceship and want to take a nap at some positive integer coordinate
. However, your spaceship has identified
threats across space, each at positive integer coordinates
. Multiple threats may be at the same coordinate.
The safety value at a coordinate is the sum of the manhattan distances from the coordinate to each threat. Formally, the safety value at is:
You want to nap as safely as possible. Can you find the maximum safety value of a coordinate in space?
Constraints
Subtask 1 [35%]
Subtask 2 [65%]
No additional constraints.
Input Specification
The first line of input will contain two space-separated integers and
.
The next lines will contain
integers
,
, and
.
Output Specification
Output one integer, the maximum safety value of a coordinate in space.
Sample Input 1
3 2
1 1 1
2 3 2
Sample Output 1
8
Sample Input 2
12346583 5
1 5 2345
1234 634 1234
999 999 999
12340000 12341230 12340000
12346583 9238732 12346580
Sample Output 2
114237170
Comments