def distanceSquared(a,b):
    """Squared L2 distance"""
    if len(a)!=len(b): raise RuntimeError('Vector dimensions not equal')
    sum=0
    for i in range(len(a)):
        sum = sum + (a[i]-b[i])*(a[i]-b[i])
    return sum