def dot(u, v, w, a, b):
    """
    Returns a special dot product of the vectors `u = (u_{1}, u_{2})` and
    `v = (v_{1}, v_{2})` which is defined in order to reduce solution of
    the congruence equation `X^2 - aZ^2 \\equiv 0 \\ (mod \\ b)`.

    """
    u_1, u_2 = u
    v_1, v_2 = v
    return (w * u_1 + b * u_2) * (w * v_1 + b * v_2) + abs(a) * u_1 * v_1
