def compare_versions(first, second):
    """
    Compare two versions with format `X.Y.Z`.

    :param first: first version string
    :param second: second version string
    :returns: 0 if equal, <0 if first < second, >0 if second < first
    """
    first = list(map(int, first.split('.')))
    second = list(map(int, second.split('.')))

    for i in range(3):
        diff = first[i] - second[i]
        if diff != 0:
            return diff

    return 0