import java.util.HashMap;
import java.util.Map;
public class Solution {
public static boolean isValidPair(int[] arr, int n, int k, int m) {
if (n % 2 != 0) {
return false;
}
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
int remainder = arr[i] % k;
map.put(remainder, map.getOrDefault(remainder, 0) + 1);
}
for (int i = 0; i < n; i++) {
int value = (m - arr[i] % k + k) % k;
if (map.containsKey(value)) {
int frequency = map.get(value);
if (frequency > 0) {
map.put(value, frequency - 1);
} else {
return false;
}
} else {
return false;
}
}
return true;
}
}