Halloween Array
Source: codechef
Difficulty: 1817

Halloween Array
There is an array of$N$integers, and a range$[L, R]$.
Let$f(A) = \prod_{1 \le i < j \le N} (A_i \oplus A_j)$. Informally,$f(A)$is the product of all pairwise XOR's of the array$A$.
If the resulting value lies between$L$and$R$(both inclusive), we call such an array a
Halloween array
.
Given an array, determine whether it is a
Halloween array
or not. Print$\text{YES}$or$\text{NO}$accordingly.
Input Format
The first line of input will contain a single integer$T$, denoting the number of test cases.
Each test case consists of multiple lines of input.
The first line of input contains$N$,$L$and$R$- the size of the array, and the left and right bounds of the interval respectively.
The second line contains$N$space-separated integers -$A_1, A_2, ..., A_N$.
Output Format
Output on a new line$\text{YES}$if the array is a halloween array else$\text{NO}$.
It is allowed to output each character in either case.$\text{yes}$,$\text{YeS}$will also be considered as a positive response.
Constraints$1 \le T \le 10^4$$2 \le N \le 2 \cdot 10^5$$0 \le A_i \le 10^9$$0 \le L \le R \le 10^9$The sum of$N$over all test cases does not exceed$2 \cdot 10^5$Sample 1:
Explanation:
Test Case 1
:$f(A) = (1 \oplus 3) = 2$.$2$lies between$0$and$10$, hence it is a Halloween array.
Test Case 2
:$f(A) = 2$.$2$does not lie between$3$and$4$.

Sample Input:
2
2 0 10
1 3
2 3 4
1 3

Sample Output:
YES
NO

C++ solution:
/*
 
    ✨✨✨✨✨  ॐ श्री गणेशाय नमः  ✨✨✨✨✨
 
 */

#include <bits/stdc++.h>
using namespace std;

// ---------- MACROS ----------
#define int long long
#define ull unsigned long long
#define D double
#define ui unsigned int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define debug(x) cerr << #x << " = " << (x) << endl;
#define sz(x) (int)(x.size())
#define maxidx(A) (A.empty() ? -1 : (std::max_element(all(A)) - A.begin()))
#define minidx(A) (A.empty() ? -1 : (std::min_element(all(A)) - A.begin()))
#define fsort(A) std::sort(A.begin(), A.end())
#define rsort(A) std::sort(A.rbegin(), A.rend())
#define rev(A) std::reverse(A.begin(), A.end())
#define vecin(n,A) for(int i = 0; i < n; i++) { cin >> A[i]; }
#define vecout(A) for(int i = 0; i < A.size(); i++) { cout << A[i] << " "; } cout << endl;
#define print(A) cout<<A<<endl

// ---------- VECTOR MACROS ----------
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>

// ---------- LOOP MACROS ----------
#define fr(i, n) for (int i = 0; i < (n); i++)
#define fri(i, a, n) for (int i = (a); i <= (n); i++)

// ---------- OUTPUT MACROS ----------
#define nl cout << "\n"

// returns max element form vector
template <typename T>
inline T maxi(vector<T>& A) { 
    return *max_element(A.begin(), A.end()); 
}

// returns max element form vector
template <typename T>
inline T mini(vector<T>& A) { 
    return *min_element(A.begin(), A.end()); 
}

// Overload >> operator for vector input
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
    for (auto &x : v) in >> x;
    return in;
}

// Overload << operator for vector output (with endl at the end)
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
    for (const auto &x : v) out << x << " ";
    out << endl; // Add newline after printing the vector
    return out;
}

// ---------- CONSTANTS ----------
const int MOD = 1e9 + 7;
const int INF = 1e18;

// ---------- DEBUGGING ----------
template <typename T> void printvector(vector<T> &v) { for (auto &x : v) cout << x << " "; cout << endl; }
template <typename T, typename U> void printmap(map<T, U> &m) { for (auto &p : m) cout << p.first << " -> " << p.second << endl; }
template <typename... Args> void dbg(Args... args) { ((cerr << args << " "), ...); cerr << endl; }

// ---------- MATH FUNCTIONS ----------
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int countSetBits(int n) { return __builtin_popcountll(n); }

// Fast exponentiation (Binary Exponentiation)
int power(int a, int b, int m = MOD) {
    int res = 1;
    while (b) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}

// ---------- PRIME UTILITIES ----------
// Sieve of Eratosthenes to find all primes up to `n`
vector<int> sieve(int n) {
    vector<bool> is_prime(n + 1, true);
    vector<int> primes;
    is_prime[0] = is_prime[1] = false;

    for (int i = 2; i * i <= n; i++) {
        if (is_prime[i]) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) primes.push_back(i);
    }
    return primes;
}


// Check if a number is prime
bool isprime(int n) {
    if (n < 2) return false;
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

// ---------- SEARCHING & SORTING ----------
// binary search
int bs(vector<int> &arr, int target) {
    int lo = 0, hi = sz(arr) - 1;
    while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        if (arr[mid] == target) return mid;
        else if (arr[mid] < target) lo = mid + 1;
        else hi = mid - 1;
    }
    return -1; // Not found
}

// Custom comparator for sorting in descending order
bool cmp_desc(int a, int b) { return a > b; }


// ---------- MAIN SOLUTION ----------


 
void solve() {
    int N;
        long long L, R;
        cin >> N >> L >> R;
        vector<int> A(N);
        for (int i = 0; i < N; ++i) cin >> A[i];

        if (N == 1) {
            cout << (L <= 1 && 1 <= R ? "YES" : "NO") << "\n";
            return;
        }

        sort(A.begin(), A.end());

        int zero =0;
        long long product = 1;
        for (int i = 0; i < N && !zero; ++i) {
            for (int j = i + 1; j < N; ++j) {
                long long xor_val = A[i] ^ A[j];
                if (xor_val == 0) {
                    zero = 1;
                    break;
                }
                if (product > R / xor_val) {
                    product = R + 1;
                    break;
                }
                product *= xor_val;
            }
        }

        if (zero) product = 0;

        cout << (L <= product && product <= R ? "YES" : "NO") <<endl;


}

int32_t main() {
    fast_io();  
    int t = 1;
    cin >> t;  
    while (t--) {
        solve();
    }
}

Go solution:
package main

import (
    "bufio"
    "fmt"
    "os"
)

func calculateF(arr []int, n int) int {
    uniqueElements := make(map[int]struct{})
    for _, num := range arr {
        uniqueElements[num] = struct{}{}
    }

    if len(uniqueElements) < n {
        return 0
    }

    result := int64(1)
    for i := 0; i < n; i++ {
        for j := i + 1; j < n; j++ {
            result *= int64(arr[i] ^ arr[j])
            if result > 1e18 {
                return int(result)
            }
        }
    }

    return int(result)
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    var t int
    fmt.Fscan(reader, &t)

    for ; t > 0; t-- {
        var n, l, r int
        fmt.Fscan(reader, &n, &l, &r)

        arr := make([]int, n)
        for i := 0; i < n; i++ {
            fmt.Fscan(reader, &arr[i])
        }

        fA := calculateF(arr, n)
        if fA >= l && fA <= r {
            fmt.Fprintln(writer, "YES")
        } else {
            fmt.Fprintln(writer, "NO")
        }
    }
}

Java solution:
import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while(t-- > 0){
            String fl[] = br.readLine().split(" ");
            int n=Integer.parseInt(fl[0]);
            long l=Integer.parseInt(fl[1]);
            long r = Integer.parseInt(fl[2]);
            
            String [] av = br.readLine().split(" ");
            int arr[]= new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(av[i]);
            }
            Arrays.sort(arr);

            boolean hasDuplicates = false;
            for (int i = 0; i < n - 1; i++) {
                if (arr[i] == arr[i + 1]) {
                    hasDuplicates = true;
                    break;
                }
            }

            if (hasDuplicates) {
                if (l <= 0 && r >= 0) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
                continue;
            }
             long product = 1;
            boolean productOverflow = false;
            outer: for (int i = 0; i < n - 1; i++) {
                for (int j = i + 1; j < n; j++) {
                    long xor = arr[i] ^ arr[j];
                    product *= xor;

                    if (product > r) {
                        productOverflow = true;
                        break outer;
                    }
                }
            }

            if (productOverflow || product < l || product > r) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }

    }
}

JavaScript solution:
/* -------------------------------------------------------- */
/*   ( The Authentic JS CodeBuff )
 ___ _                      _              _ 
 | _ ) |_  __ _ _ _ __ _ __| |_ __ ____ _ (_)
 | _ \ ' \/ _ | '_/ _ / _ \ V  V / _ || |
 |___/_||_\__,_|_| \__,_\__,_|\_/\_/\__,_|/ |
                                        |__/ 
 */
/* ---------------------------------------------------------   */
/*    Youtube: https://youtube.com/@code-with-Bharadwaj        */
/*    Github : https://github.com/Manu577228                  */
/* ----------------------------------------------------------- */

// Template Starts here Fast IO!

const V8Flags = [
    '--max-old-space-size=4096', '--max-semi-space-size=16', '--stack-size=65536', '--reclaim-unused-memory',
    '--gc-interval=100', '--expose-gc', '--gc-global', '--optimize-for-speed',
    '--always-opt', '--max-inlined-source-size=600', '--max-inlined-bytecode-size=600', '--turbo-inline-js-wasm-calls',
    '--turbo', '--turbo-optimizer', '--force-optimization', '--no-lazy',
    '--no-lazy-inner-functions', '--optimize-for-size', '--initial-heap-size=64', '--max-heap-size=192',
    '--use-strict', '--predictable', '--single-threaded-gc', '--no-inline-new',
    '--opt', '--no-lazy-deserialization', '--no-browser-globals', '--turbo-inline-array-builtins',
    '--fast-math', '--fuzzing', '--minor-mc', '--incremental-marking',
    '--concurrent-recompilation', '--stress-compaction', '--experimental-flush-embedded-blob-icache', '--experimental-value-unavailable'
];

if (V8Flags.length > 0) process.execArgv.push('--v8-options=' + V8Flags.join(' '));

let inputBuffer = Buffer.allocUnsafe(1e7);
let inputIndex = 0,
        inputLength = 0;
let outputBuffer = Buffer.allocUnsafe(1e7);
let outputIndex = 0;

let fs = require('fs');
inputLength = fs.readSync(process.stdin.fd, inputBuffer, 0, inputBuffer.length, null);

function readInt() {
        let n = 0,
                s = 1;
        while (inputBuffer[inputIndex] < 48 || inputBuffer[inputIndex] > 57) {
                if (inputBuffer[inputIndex] === 45) s = -1;
                inputIndex++;
        }
        while (inputIndex < inputLength && inputBuffer[inputIndex] >= 48 && inputBuffer[inputIndex] <= 57) {
                n = n * 10 + (inputBuffer[inputIndex++] - 48);
        }
        return BigInt(n * s);
}

function writeStr(s) {
        for (let i = 0; i < s.length; i++) {
                outputBuffer[outputIndex++] = s.charCodeAt(i);
        }
        outputBuffer[outputIndex++] = 10;
}

// Template Ends here!

let t = Number(readInt());
while (t--) {
        let n = Number(readInt());
        let l = readInt();
        let r = readInt();
        let a = new Array(n);
        
        for (let i = 0; i < n; i++) a[i] = Number(readInt());
        
        a.sort((x, y) => x - y);
        
        let h = false;
        for (let i = 1; i < n; i++) {
                if (a[i] === a[i - 1]) {
                        h = true;
                        break;
                }
        }
        
        if (h) {
                writeStr(l <= 0 && 0 <= r ? "YES" : "NO");
        } else {
                if (n >= 13) {
                        let e = false;
                        let p = 1n;
                        
                        for (let i = 0; i < n && !e; i++) {
                                for (let j = i + 1; j < n && !e; j++) {
                                        let x = BigInt(a[i] ^ a[j]);
                                        if (x === 0n) {
                                                p = 0n;
                                                break;
                                        }
                                        if (p > r / x) {
                                                e = true;
                                                break;
                                        }
                                        p *= x;
                                }
                        }
                        
                        if (e) {
                                writeStr("NO");
                        } else {
                                writeStr(p >= l && p <= r ? "YES" : "NO");
                        }
                } else {
                        let p = 1n;
                        let e = false;
                        
                        for (let i = 0; i < n && !e; i++) {
                                for (let j = i + 1; j < n && !e; j++) {
                                        let x = BigInt(a[i] ^ a[j]);
                                        if (x === 0n) {
                                                p = 0n;
                                                break;
                                        }
                                        if (x !== 0n && p > r / x) {
                                                e = true;
                                                break;
                                        }
                                        p *= x;
                                }
                        }
                        
                        writeStr(!e && p >= l && p <= r ? "YES" : "NO");
                }
        }
}

fs.writeSync(process.stdout.fd, outputBuffer.slice(0, outputIndex));

Python solution:
import sys
from math import prod

input = sys.stdin.read
data = input().split()

idx = 0
T = int(data[idx])
idx += 1
res = []

while T > 0:
    T -= 1
    N, L, R = int(data[idx]), int(data[idx+1]), int(data[idx+2])
    A = list(map(int, data[idx+3:idx+3+N]))
    idx += 3 + N

    if len(set(A)) != N:
        res.append("YES" if L <= 0 <= R else "NO")
        continue

    if N > 12:
        fA = 1
        exceeded = False
        for i in range(N):
            for j in range(i + 1, N):
                xor_val = A[i] ^ A[j]
                fA *= xor_val
                if fA > R:
                    exceeded = True
                    break
            if exceeded:
                break
        if exceeded:
            res.append("NO")
        else:
            res.append("YES" if L <= fA <= R else "NO")
    else:
        xor_vals = [A[i] ^ A[j] for i in range(N) for j in range(i + 1, N)]
        fA = prod(xor_vals)
        res.append("YES" if L <= fA <= R else "NO")

sys.stdout.write("\n".join(res) + "\n")

Ruby solution:
def solve
  input = $stdin.read.split
  idx = 0
  test_cases = input[idx].to_i
  idx += 1
  res = []

  while test_cases > 0
    test_cases -= 1
    n = input[idx].to_i
    l = input[idx + 1].to_i
    r = input[idx + 2].to_i
    idx += 3
    a = input[idx, n].map(&:to_i)
    idx += n

    if a.uniq.size != n
      res << (l <= 0 && 0 <= r ? "YES" : "NO")
      next
    end

    if n > 12
      product = 1
      exceeded = false
      (0...n).each do |i|
        (i + 1...n).each do |j|
          xor_val = a[i] ^ a[j]
          product *= xor_val
          if product > r
            exceeded = true
            break
          end
        end
        break if exceeded
      end
      if exceeded
        res << "NO"
      else
        res << (l <= product && product <= r ? "YES" : "NO")
      end
    else
      xor_vals = []
      (0...n).each do |i|
        (i + 1...n).each do |j|
          xor_vals << (a[i] ^ a[j])
        end
      end
      product = xor_vals.inject(1, :*)
      res << (l <= product && product <= r ? "YES" : "NO")
    end
  end

  puts res.join("\n")
end

solve