

Given two arrays of non-negative numbers p and q representing discrete probability distributions over the same support, write a function that returns the Kullback-Leibler divergence KL(p || q) using numerically stable computation. The function should normalize inputs if needed, reject invalid distributions, and avoid taking log(0) by using a small positive epsilon.
Example 1:
Input: p = [0.5, 0.5], q = [0.9, 0.1]
Output: 0.5108256238
Explanation: KL(p || q) = 0.5*log(0.5/0.9) + 0.5*log(0.5/0.1).
Example 2:
Input: p = [1, 0, 0], q = [0.8, 0.1, 0.1]
Output: 0.2231435513
Explanation: Zero-probability terms in p contribute 0, and q is clipped away from 0 for stability.
1 <= len(p) == len(q) <= 10^5p[i] >= 0 and q[i] >= 01e-9 is acceptable