public boolean isValid(int[] a, int mod, int k) {
    int[] data = new int[mod];

    int over = 0;
    for (int x = 0; x < a.length; x++) {
      int index = a[x] % mod;
      data[index]++;
      if (data[index] > 1) {
        over++;
        if (over > k)
          return false;
      }
    }
    return true;
  }