💥💥 Beats 100% on runtime and memory [EXPLAINED]
IntuitionThe key to solving this problem is understanding the relative positions of x and y, and how the number of pairs can be computed based on the distance b
# Intuition
The key to solving this problem is understanding the relative positions of x and y, and how the number of pairs can be computed based on the distance between them and the rest of the elements. You need to break the problem into different zones where x and y are located, and count how many possible pairings are possible based on these zones.

# Approach
We calculate pairings based on three main sections: the left arm (before x), the loop (between x and y), and the right arm (after y), updating intermediate values using an accumulator array. The result is obtained by adding up values in the accumulator, adjusting for different distances in each section.

# Complexity
- Time complexity:
O(n) because we only loop through the array a few times and perform constant time operations during each iteration.

- Space complexity:
O(n) due to the usage of arrays (acc and res) to store intermediate and final results.

# Code
```kotlin []
class Solution {

    fun countOfPairs(n: Int, x: Int, y: Int): IntArray {
        val acc = IntArray(100001) { 0 }  // Array to store intermediate values for calculation
        val res = IntArray(n)  // Array to store the final result

        // Case when the difference between x and y is 1 or less, return the result directly
        if (Math.abs(x - y) <= 1) {
            for (i in 0 until n) res[i] = (n - i - 1) * 2
            return res
        }

        // Reset accumulator array and adjust x and y values if necessary
        acc.fill(0, 0, n + 1)
        var x = x
        var y = y
        if (x > y) {
            // Swap x and y if x is greater than y
            val t = x
            x = y
            y = t
        }

        // Adjust the range of x and y to fit within the bounds of the problem
        if (x - 1 > n - y) {
            val t = n - y + 1
            y = n - x + 1
            x = t
        }

        // Handling both x and y being on the same loop segment
        var c = y - x + 1
        val h = (y - x) shr 1
        acc[1] += 2 * c  // Update accumulator based on the number of steps between x and y
        acc[h + 1] -= 2 * c  // Adjust for the transition between loop sections

        // Handle the case when the count of steps is even
        if ((c and 1) == 0) {
            acc[c shr 1] += c
            acc[(c shr 1) + 1] -= c
        }

        // Handling the sections on the left and right arms (before x and after y)
        val la = x - 1
        val ra = n - y
        if (la > 0) {
            acc[1] += (la - 1) shl 1  // Update the left arm range
            for (i in 2..la) {
                acc[i] -= 2  // Adjust intermediate values for the left arm
            }
        }
        if (ra > 0) {
            acc[1] += (ra - 1) shl 1  // Update the right arm range
            for (i in 2..ra) {
                acc[i] -= 2  // Adjust intermediate values for the right arm
            }
        }

        // Handle the interaction between left and right arms
        for (i in 1..la) {
            acc[i + 2] += 2
            acc[i + 2 + ra] -= 2
        }

        // Handle the case when one part is on the loop and the other on an arm
        for (i in 1..la) {
            acc[i] += 2
            acc[i + h + 1] -= 2
            acc[i + 1] += 2
            acc[i + h + 1 + ((c and 1) xor 1)] -= 2
        }
        for (i in 1..ra) {
            acc[i] += 2
            acc[i + h + 1] -= 2
            acc[i + 1] += 2
            acc[i + h + 1 + ((c and 1) xor 1)] -= 2
        }

        // Calculate the final result by summing up the values in the accumulator
        res[0] = acc[1]
        for (i in 1 until n) {
            res[i] = res[i - 1] + acc[i + 1]
        }

        return res
    }
}

```
['Array', 'Math', 'Graph', 'Binary Indexed Tree', 'Heap (Priority Queue)', 'Prefix Sum', 'Kotlin']