import static java.
lang.
Integer.
max;
public class TwoDiagonals {
public int maxPoints(int[] x, int[] y) {
int n = x.length;
int max_coord = 0;
for(int i = 0; i < n; ++i) {
max_coord = max(max_coord, max(x[i], y[i]));
}
max_coord++;
boolean[][] grid = new boolean[max_coord][max_coord];
int[] cnt_sum = new int[2*max_coord+1];
int[] cnt_diff = new int[2*max_coord+1];
for(int i = 0; i < n; ++i) {
grid[x[i]][y[i]] = true;
cnt_sum[x[i]+y[i]]++;
cnt_diff[x[i]-y[i]+max_coord]++;
}
int answer = 0;
for(int sum = 0; sum < cnt_sum.length; ++sum)
for(int diff = 0; diff < cnt_diff.length; ++diff) {
int together = cnt_sum[sum] + cnt_diff[diff];
// x + y = sum
// x - y = diff - max_coord
int x2 = sum + diff - max_coord;
int y2 = sum - diff + max_coord;
if(x2 % 2 == 0 && y2 % 2 == 0) {
int x1 = x2 / 2;
int y1 = y2 / 2;
if(0 <= x1 && x1 < max_coord && 0 <= y1 && y1 < max_coord && grid[x1][y1])
--together;
}
answer = max(answer, together);
}
return answer;
}
}
aW1wb3J0IHN0YXRpYyBqYXZhLmxhbmcuSW50ZWdlci5tYXg7CgpwdWJsaWMgY2xhc3MgVHdvRGlhZ29uYWxzIHsKCglwdWJsaWMgaW50IG1heFBvaW50cyhpbnRbXSB4LCBpbnRbXSB5KSB7CgkJaW50IG4gPSB4Lmxlbmd0aDsKCQlpbnQgbWF4X2Nvb3JkID0gMDsKCQlmb3IoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CgkJCW1heF9jb29yZCA9IG1heChtYXhfY29vcmQsIG1heCh4W2ldLCB5W2ldKSk7CgkJfQoJCW1heF9jb29yZCsrOwoJCWJvb2xlYW5bXVtdIGdyaWQgPSBuZXcgYm9vbGVhblttYXhfY29vcmRdW21heF9jb29yZF07CgkJaW50W10gY250X3N1bSA9IG5ldyBpbnRbMiptYXhfY29vcmQrMV07CgkJaW50W10gY250X2RpZmYgPSBuZXcgaW50WzIqbWF4X2Nvb3JkKzF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