import re


def reformat_url(url: str) -> str:
    """Reformat url

    :param str url: user input url
    :exception: ValueError when url is not valid or malformed
    :return: a reformatted url
    """
    um = re.match(r"(http[s]?://)?(w{3}\.)?(.*)", url)
    if not um or not um.group(3):
        raise ValueError(f"Invalid URL: {url}")

    http, www, loc = um.groups()

    if not http:
        return f"http://{url}"
    return url