"""
Solution: a difficulty router and a majority vote, measured (Lab 02, Scripts 4-5).
"""
from collections import Counter


def route(classifier_reply: str) -> str:
    return "hard" if "HARD" in classifier_reply.upper() else "easy"


def majority_vote(finals: list[str]) -> tuple[str, int]:
    counts = Counter(f.strip().lower() for f in finals)
    winner, votes = counts.most_common(1)[0]
    return winner, votes


def check_labels(instant_ok: list[dict[str, bool]], labels: dict[str, str]) -> dict[str, list[str]]:
    needs_more = {q for run in instant_ok for q, ok in run.items() if not ok}
    return {
        "should_be_hard": sorted(q for q in needs_more if labels[q] == "easy"),
        "could_be_easy": sorted(q for q, label in labels.items() if label == "hard" and q not in needs_more),
    }


def easy_share(think_costs: dict[str, float], labels: dict[str, str]) -> float:
    total = sum(think_costs.values())
    easy = sum(cost for q, cost in think_costs.items() if labels[q] == "easy")
    return easy / total if total else 0.0
