Problem: Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times.
Select either first or last element from the given array.
Either increment the selected element by 1 or delete the selected element.

Sample Input: arr[] = {10, 2, 10, 5}, X = 3, K = 3
Sample Output: 1
Explanation:
XOR of the given array = 7. The only possible array satisfying the condition is {10, 2, 10, 8}, obtained by incrementing the last array element thrice.

Solution (java):
// Java program for the above approach
import java.util.ArrayList;
class InfobayAI{

// Stores the final answer
static int ans = 0;

// Utility function to count arrays
// having at least K elements exceeding
// XOR of all given array elements
public static void countArraysUtil(ArrayList<Integer> arr,
                     int X, int K,
                     int xorVal)
{
    // If no operations are left
    if (X == 0) {

        // Stores the count of
        // possible arrays
        int cnt = 0;

        // Count array elements are
        // greater than XOR
        for (int i = 0; i < arr.size(); i++) {

            if (arr.get(i) > xorVal)
                cnt++;
        }
        if (cnt >= K)
            ans++;
        return;
    }
    
    // Stores first element
    int temp = arr.get(0);

    // Delete first element
    arr.remove(0);

    // Recursive call
    countArraysUtil(arr, X - 1, 
                    K, xorVal);

    // Insert first element into vector
    arr.add(0, temp);

    // Stores the last element
    temp = arr.get(arr.size() - 1);

    // Remove last element from vector
    arr.remove(arr.size() - 1);

    // Recursive call
    countArraysUtil(arr, X - 1, 
                    K, xorVal);

    // Push last element into vector
    arr.add(temp);

    // Increment first element
    arr.set(0, arr.get(0) + 1);
  
    // Recursive call
    countArraysUtil(arr, X - 1,
                    K, xorVal);
  
    // Decrement first element
    arr.set(0, arr.get(0) - 1);


    // Increment last element
    arr.set(arr.size() - 1, arr.get(arr.size() - 1) + 1);
  
    // Recursive call
    countArraysUtil(arr, X - 1,
                    K, xorVal);
  
    // Decrement last element
    arr.set(arr.size() - 1, arr.get(arr.size() - 1) - 1);

}

// Function to find the count of 
// arrays having atleast K elements 
// greater than XOR of array
public static void countArrays(ArrayList<Integer> arr, 
                 int X, int K)
{
    // Stores the XOR value
// of original array
    int xorVal = 0;

    // Traverse the vector
    for (int i = 0; i < arr.size(); i++)
        xorVal = xorVal ^ arr.get(i);

    countArraysUtil(arr, X, K, xorVal);

    // Print the answer
    System.out.println(ans);
}

// Driver Code
public static void main(String arg[])
{
  
    // Given vector
    int[] input = {10, 2, 10, 5};
    
    // Convert the input as ArrayList
    ArrayList<Integer> arr = new ArrayList<Integer>();

    for(int i : input){
        arr.add(i);
    }
     

    // Given value of X & K
    int X = 3, K = 3;

    countArrays(arr, X, K);
}
}