from typing import Union
from typing import List
from typing import Tuple


def convert_pairs_to_comparison_counts(vals1: Union[int, List[float]], vals2: Union[int, List[float]]) \
        -> Tuple[int, int]:
    """
    If vals1 and vals2 are both ints, they are assumed already to be counts and are returned as is.
    Otherwise, they must be lists of the same length and are paired item by item. We return (n1, n2), where
    n1 is the number of pairs (val1, val2) from the two lists such that val1 < val2, and n2 is the number
    of pairs such that val1 > val2 (so equal pairs do not contribute to either count).
    """
    if isinstance(vals1, int) and isinstance(vals2, int):
        # The arguments are already counts.
        return vals1, vals2
    if isinstance(vals1, list) and isinstance(vals2, list) and len(vals1) == len(vals2):
        n1 = 0
        n2 = 0
        for (v1, v2) in zip(vals1, vals2):
            d = v2 - v1
            if d > 0:
                n2 += 1
            elif d < 0:
                n1 += 1
        return n1, n2
    raise ValueError('Arguments must both be ints or both be lists of the same length')