from typing import List
import collections


def molecular_formula_from_symbols(symbols: List[str], order: str = "alphabetical") -> str:
    """
    Returns the molecular formula for a list of symbols.

    Parameters
    ----------
    symbols: List[str]
        List of chemical symbols
    order: str, optional
        Sorting order of the formula. Valid choices are "alphabetical" and "hill".

    Returns
    -------
    str
        The molecular formula.
    """

    supported_orders = ["alphabetical", "hill"]
    order = order.lower()
    if order not in supported_orders:
        raise ValueError(f"Unsupported molecular formula order: {order}. Supported orders are f{supported_orders}.")
    count = collections.Counter(x.title() for x in symbols)
    element_order = sorted(count.keys())

    if order == "hill" and "C" in element_order:
        if "H" in element_order:
            element_order.insert(0, element_order.pop(element_order.index("H")))
        element_order.insert(0, element_order.pop(element_order.index("C")))

    ret = []
    for k in element_order:
        c = count[k]
        ret.append(k)
        if c > 1:
            ret.append(str(c))

    return "".join(ret)