def fill_missing_values_with_median(df):
    """Fill missing values with median considering sex differences."""

    df["height"] = df["height"].fillna(df.groupby("sex")["height"].transform("median"))
    df["weight"] = df["weight"].fillna(df.groupby("sex")["weight"].transform("median"))
    df["ac"] = df["ac"].fillna(df.groupby("sex")["ac"].transform("median"))

    return df