Counting pairs of numbers that differ by a given amount
Your solution is \$O(X^2)\$ which is too slow for \$X\approx 10^5\$.

Instead of checking differences with two nested loops, you should just loop over the first element a and perform binary search to find the number of elements of the form a+Y. This will reduce the complexity to \$O(X \log X)\$ which will be fast enough.