@leakey I just finished the following solution in C. Sorry about mentioning `Hash or Map`

in my last reply, which is really a hurt in C. So here is a solution in C using `Binary Search`

to reduce the time complexity.

```
int compare_ints(const void* a, const void* b)
{
int arg1 = *(const int*)a;
int arg2 = *(const int*)b;
if (arg1 < arg2) return -1;
if (arg1 > arg2) return 1;
return 0;
}
int lowerBound(int*arr, int size, int target){
int l = 0, r = size-1;
while(l <= r){
int m = l+((r-l)>>1);
if(arr[m] >= target) r = m-1;
else l = m+1;
}
return arr[l]==target? l : -1;
}
int upperBound(int*arr, int size, int target){
int l = 0, r = size-1;
while(l <= r){
int m = l+((r-l)>>1);
if(arr[m] <= target) l = m+1;
else r = m-1;
}
return arr[r]==target? r : -1;
}
int fourSumCount(int* A, int ASize, int* B, int BSize, int* C, int CSize, int* D, int DSize) {
int *arr1 = (int*)malloc(sizeof(int)*(ASize*BSize)), *arr2 = (int*)malloc(sizeof(int)*(CSize*DSize));
int k = 0;
for(int i = 0; i < ASize; ++i)
for(int j = 0; j < BSize; ++j)
arr1[k++] = A[i]+B[j];
k = 0;
for(int i = 0; i < CSize; ++i)
for(int j = 0; j < DSize; ++j)
arr2[k++] = C[i]+D[j];
qsort(arr1, ASize*BSize, sizeof(int), compare_ints);
qsort(arr2, CSize*DSize, sizeof(int), compare_ints);
int sumCount = 0;
for(int i = 0; i < ASize*BSize; ++i){
int l = lowerBound(arr2, CSize*DSize, -arr1[i]);
if(l != -1){
int r = upperBound(arr2, CSize*DSize, -arr1[i]);
sumCount += r-l+1;
}
}
return sumCount;
}
```