# -*- coding: utf-8 -*-
"""2025年度 女子学院中学校 (JG-E0021) の独立検証。
主解法 (比・線分図・面積の分割・逆算) とは別経路 (全探索・座標の厳密/高精度計算・sympy の連立方程式・暦ライブラリ) で答えを再計算する。
解答は出版社作成 (data/official_answers_overrides/JG-E0021.json)。図の読み取り (どの頂点か・どの列か) は目視で確認した内容を座標・表に直して使う。"""
from fractions import Fraction as F
from decimal import Decimal
import datetime, itertools
import mpmath
import sympy as sp

mpmath.mp.dps = 60            # 角度の検証は 60 桁の任意精度 (Python の float は使わない)
CHECKS = {}
E = "JG-E0021"


def fr(x):
    """sympy の有理数 → Fraction。"""
    x = sp.Rational(x)
    return F(int(x.p), int(x.q))


def dec(x):
    """Fraction → 小数表記の文字列 (37.5 など)。"""
    x = F(x)
    if x.denominator == 1:
        return str(x.numerator)
    return format((Decimal(x.numerator) / Decimal(x.denominator)).normalize(), "f")


# ───────────── 大問 1 (1): □ を sympy で厳密に解く ─────────────
def q1s1():
    x = sp.Symbol("x")
    lhs = sp.Rational(87, 10) + ((x + sp.Rational(1, 4)) * sp.Rational(4375, 1000) + sp.Rational(7, 12)) / (sp.Rational(1, 6) + sp.Rational(1, 9))
    sol = sp.solve(sp.Eq(lhs, sp.Rational(2025, 100)), x)
    assert len(sol) == 1
    return fr(sol[0])
CHECKS[f"{E}-Q01-S01"] = {"method": "sympy で方程式を厳密に解く (主解法の外側からの逆算とは別経路)", "compute": q1s1,
                          "extra": [(lambda: F(87, 10) + ((F(7, 20) + F(1, 4)) * F(4375, 1000) + F(7, 12)) / (F(1, 6) + F(1, 9)) == F(2025, 100), "7/20 を元の式に代入すると 20.25")]}


# ───────────── 大問 1 (2): 三つの角度を座標で求める ─────────────
def rad(d):
    return mpmath.mpf(d) * mpmath.pi / 180


def angle_deg(u, v):
    cu = (u[0] * v[0] + u[1] * v[1]) / (mpmath.sqrt(u[0] ** 2 + u[1] ** 2) * mpmath.sqrt(v[0] ** 2 + v[1] ** 2))
    return mpmath.acos(cu) * 180 / mpmath.pi


def near_int(x, tol=mpmath.mpf(10) ** -40):
    r = int(mpmath.nint(x))
    assert abs(x - r) < tol, x          # 60 桁計算で整数度に 1e-40 以内で一致することを確認
    return r


def ang_a():
    P = lambda deg: (mpmath.cos(rad(deg)), mpmath.sin(rad(deg)))
    T, UL, LL, LR, UR = P(90), P(162), P(234), P(306), P(18)            # 正五角形 (外接円半径 1) の頂点
    d = (LR[0] - UL[0], LR[1] - UL[1])
    t = ((UR[0] - UL[0]) * d[0] + (UR[1] - UL[1]) * d[1]) / (d[0] ** 2 + d[1] ** 2)
    H = (UL[0] + t * d[0], UL[1] + t * d[1])                           # UR から対角線 UL-LR への垂線の足
    a1, b1 = LR[0] - T[0], LR[1] - T[1]; a2, b2 = H[0] - UR[0], H[1] - UR[1]
    det = -a1 * b2 + a2 * b1
    rx, ry = UR[0] - T[0], UR[1] - T[1]
    s = (rx * (-b2) + a2 * ry) / det
    X = (T[0] + s * a1, T[1] + s * b1)                                  # 直線 T-LR と垂線 UR-H の交点
    return near_int(angle_deg((T[0] - X[0], T[1] - X[1]), (UR[0] - X[0], UR[1] - X[1])))


def ang_b():
    c, s_ = mpmath.cos(rad(71)), mpmath.sin(rad(71))
    A = (c, s_); D = (1 + c, s_)                                        # B=(0,0), C=(1,0), 辺の長さ 1 のひし形
    t = 2 * c                                                           # E=t(cos71°, sin71°) で CE=CD=1 (E≠B)
    E_ = (t * c, t * s_)
    x = (D[0] ** 2 - E_[0] ** 2 - (s_ - E_[1]) ** 2) / (2 * (D[0] - E_[0]))   # AD 上 (y=sin71°) で FE=FD
    assert A[0] <= x <= D[0]                                            # F は辺 AD 上
    Fp = (x, s_)
    return near_int(angle_deg((A[0] - Fp[0], A[1] - Fp[1]), (E_[0] - Fp[0], E_[1] - Fp[1])))


def ts_minus_pq(th):
    """P=(0,0), PQ=1, 角P=th° の三角形 PQR (角PQR=78°) と、QR=RS・角TSR=48° の三角形 TRS を作り TS-PQ を返す。"""
    r_ang = 102 - th
    Q = (mpmath.cos(rad(th)), mpmath.sin(rad(th)))
    PR = mpmath.sin(rad(78)) / mpmath.sin(rad(r_ang))                   # 正弦定理
    R = (PR, mpmath.mpf(0))
    QR = mpmath.sqrt((Q[0] - R[0]) ** 2 + (Q[1] - R[1]) ** 2)
    u = ((Q[0] - R[0]) / QR, (Q[1] - R[1]) / QR)                        # R から Q への向き (T はこの半直線上で Q の先)
    w = (mpmath.cos(rad(132)), mpmath.sin(rad(132)))                    # S から T への向き (角TSR=48°)
    t = QR / (u[0] - u[1] * w[0] / w[1])                                # R + t u = S + s w, S = R + (QR, 0)
    s = t * u[1] / w[1]
    return s - 1, t - QR


def ang_c():
    # ㋒ を 1°〜101° の整数で全探索 (角R=102°−㋒>0 の範囲)。TS=PQ かつ T が Q の先 (t>QR) になる ㋒ を探す
    sols = [th for th in range(1, 102) if abs(ts_minus_pq(th)[0]) < mpmath.mpf(10) ** -40 and ts_minus_pq(th)[1] > 0]
    assert len(sols) == 1
    return sols[0]


def sign_pattern_ok():
    rows = [(th,) + tuple(ts_minus_pq(th)) for th in range(1, 102)]
    valid = [(th, g) for th, g, tq in rows if tq > 0]            # T が Q の先にある (図として成立する) ㋒ だけ
    return (all(g < 0 for th, g in valid if th < 27) and all(g > 0 for th, g in valid if th > 27)
            and [th for th, g in valid if g == 0 or abs(g) < mpmath.mpf(10) ** -40] == [27])


CHECKS[f"{E}-Q01-S02"] = {"method": "㋐: 正五角形を座標に置き垂線と対角線の交点の角を高精度計算 / ㋑: ひし形を座標に置き CE=CD, FE=FD から F を解く / ㋒: ㋒ を整数で全探索し TS=PQ となる角を探す",
                          "compute": lambda: f"ア {ang_a()}度, イ {ang_b()}度, ウ {ang_c()}度",
                          "expect": "ア 54度, イ 33度, ウ 27度", "official_value": "ア 54度, イ 33度, ウ 27度",
                          "extra": [(sign_pattern_ok, "図として成立する範囲 (T が Q の先にある ㋒ ＝ 6°〜53°) で TS−PQ の符号は 27° の前後で 1 回だけ変わる (整数の解は 1 つ)")]}


# ───────────── 大問 1 (3): 5 つの整数を全探索 ─────────────
def q1s3_solutions():
    # 範囲の根拠: a<b<c<d<e, a+b+c=59 より c≥20。c+d+e=93, c<d<e より c≤30, e≤52。b<c≤30, a=59−c−b≥0。よって全員 0〜60 に入る (探索は −5〜60)
    sols = []
    for a in range(-5, 61):
        for b in range(a + 1, 61):
            c = 59 - a - b                      # 小さい順に 3 つの和 = 59
            if not (b < c <= 60):
                continue
            for d in range(c + 1, 61):
                e = 93 - c - d                  # 大きい順に 3 つの和 = 93
                if d < e <= 60 and a + b + c + d + e == 130 and a + e == 55:
                    sols.append((a, b, c, d, e))
    return sols


def q1s3():
    sols = q1s3_solutions()
    cs = {s[2] for s in sols}
    assert len(cs) == 1
    return f"① {cs.pop()}, ② {', '.join(str(e) for e in sorted({s[4] for s in sols}))}"
CHECKS[f"{E}-Q01-S03"] = {"method": "a<b<c<d<e を条件 (和 130・小 3 つ 59・大 3 つ 93・最大+最小 55) ですべて全探索",
                          "compute": q1s3, "expect": "① 22, ② 37, 38, 39", "official_value": "① 22, ② 37, 38, 39",
                          "extra": [(lambda: sorted(q1s3_solutions()) == [(16, 21, 22, 32, 39), (17, 20, 22, 33, 38), (18, 19, 22, 34, 37)], "条件を満たす 5 つの組は 3 通りだけ")]}


# ───────────── 大問 1 (4): 積み木の最少・最多を高さの割り当てで全探索 ─────────────
def q1s4():
    cols = [(1, 1), (2, 2), (3, 4), (4, 3)]      # (正面図の高さ, 真上図でその列にある場所の数) を左から
    per_col = []
    for H, n in cols:
        # 列の各場所の個数は 1〜H、列の最大が H (正面図)。割り当てをすべて列挙して列ごとの合計の集合を作る
        per_col.append({sum(hs) for hs in itertools.product(range(1, H + 1), repeat=n) if max(hs) == H})
    totals = {sum(c) for c in itertools.product(*per_col)}
    return f"最も少ない場合 {min(totals)}個, 最も多い場合 {max(totals)}個"
CHECKS[f"{E}-Q01-S04"] = {"method": "各列の各場所の個数 (1〜高さ、列の最大 = 正面図の高さ) を全列挙して合計の最小・最大を取る",
                          "compute": q1s4, "expect": "最も少ない場合 16個, 最も多い場合 29個", "official_value": "最も少ない場合 16個, 最も多い場合 29個"}


# ───────────── 大問 1 (5): 正六角形のしきつめを座標で ─────────────
def q1s5():
    s3 = sp.sqrt(3)
    def center(r, c):                            # 1 辺 1 の正六角形 (上下が頂点)。r 段目 c 番目 (0 始まり)。段が奇数なら半個ずれる
        return (s3 * (c + sp.Rational(r % 2, 2)), -sp.Rational(3, 2) * r)
    def vertex(r, c, k):                         # k = 0 上, 1 右上, 2 右下, 3 下, 4 左下, 5 左上
        cx, cy = center(r, c); ang = sp.pi / 2 - k * sp.pi / 3
        return (cx + sp.cos(ang), cy + sp.sin(ang))
    A, B, C = vertex(0, 5, 3), vertex(2, 0, 2), vertex(2, 4, 3)        # A: 1 段目右端の下の頂点, B: 3 段目左端の右下の頂点, C: 3 段目右から 2 番目の下の頂点
    area = sp.Abs((B[0] - A[0]) * (C[1] - A[1]) - (C[0] - A[0]) * (B[1] - A[1])) / 2
    ratio = sp.simplify(area / (3 * s3 / 2))     # 三角形 ABC は正六角形 (面積 3√3/2) の何個分か
    return fr(ratio) * 18
CHECKS[f"{E}-Q01-S05"] = {"method": "正六角形 (1 辺 1) の頂点座標を sympy の厳密値で置き、三角形 ABC の面積を正六角形何個分かで求めて 18 倍",
                          "compute": q1s5}


# ───────────── 大問 2: 暦ライブラリで日付を 1 日ずつ数える ─────────────
D0, D1 = datetime.date(2024, 4, 1), datetime.date(2025, 1, 31)


def days():
    return [D0 + datetime.timedelta(days=i) for i in range((D1 - D0).days + 1)]


def q2s1():
    assert D1.weekday() == 4                     # 2025年1月31日は金曜日 (問題文の (金) と一致)
    return sum(1 for d in days() if d.weekday() == 6)
CHECKS[f"{E}-Q02-S01"] = {"method": "datetime で 2024-04-01〜2025-01-31 を 1 日ずつ見て日曜日を数える (1/31 が金曜であることも確認)", "compute": q2s1,
                          "extra": [(lambda: len(days()) == 306, "期間は 306 日")]}


def q2s2():
    base = weekdays = 0
    for d in days():
        w = d.weekday()
        if w <= 4:
            base += 2; weekdays += 1             # 月〜金は必ず 2 問
        elif w == 5:
            base += 5                            # 土曜は 5 問
    # 調子が良い日 g (0〜月〜金の日数) を全探索: 合計 = base + 2g = 777
    sols = [g for g in range(weekdays + 1) if base + 2 * g == 777]
    assert len(sols) == 1
    return sols[0]
CHECKS[f"{E}-Q02-S02"] = {"method": "曜日ごとに問題数を加え、調子が良い日 g を 0〜月〜金の日数で全探索して合計 777 になる g を探す", "compute": q2s2,
                          "extra": [(lambda: sum(1 for d in days() if d.weekday() <= 4) == 220 and sum(1 for d in days() if d.weekday() == 5) == 43, "月〜金は 220 日、土曜は 43 日")]}


# ───────────── 大問 3: 立体の寸法を面ごとの表面積から全探索・連立方程式で ─────────────
def surface(p, q):
    """50 × 40 × 60 の直方体の右上を 幅 p・高さ q・奥行き 40 だけ切り取った立体の表面積を、面ごとに足し上げる。"""
    return ((50 * 40) + (60 * 40)                 # 底面・左側面
            + (50 - p) * 40                       # 高い部分の上面
            + q * 40 + p * 40                     # へこみの壁と床
            + (60 - q) * 40                       # 右側面 (低い部分)
            + 2 * (50 * 60 - p * q))              # 正面・背面の L 字形


def q3s1():
    vols = set(); n = 0
    for i in range(1, 100):                       # p = 0.5〜49.5 (0.5 刻み)
        for j in range(1, 120):                   # q = 0.5〜59.5 (0.5 刻み)
            p, q = F(i, 2), F(j, 2)
            if surface(p, q) == 13450:
                n += 1; vols.add(50 * 40 * 60 - p * q * 40)
    assert n > 0 and len(vols) == 1               # 寸法は 1 通りに決まらないが、体積は同じ値になる
    return vols.pop()
CHECKS[f"{E}-Q03-S01"] = {"method": "切り取りの幅・高さを 0.5 刻みで全探索し、面ごとの表面積が 13450 になる立体すべてで体積を計算 (どれも同じ値)", "compute": q3s1}


def q3_system():
    Q, w, q = sp.symbols("Q w q", positive=True)  # Q: 毎秒の水の量, w: 高い部分の幅, q: 切り取りの高さ
    h1 = 60 - q                                   # 低い部分の高さ = グラフの ①
    def water(z):                                 # 深さ z (≥ h1) までの水の量 = 水そうの底面積 × z − 沈んだ立体の体積
        return 3600 * z - (50 * 40 * h1 + w * 40 * (z - h1))
    eqs = [sp.Eq(water(60), 123 * Q), sp.Eq(water(50), 95 * Q), sp.Eq(surface(50 - w, q), 13450)]
    sols = sp.solve(eqs, [Q, w, q], dict=True)
    ok = [s for s in sols if 0 < s[w] < 50 and 0 < s[q] < 60 and 60 - s[q] < 50]
    assert len(ok) == 1
    return ok[0], (Q, w, q)


def q3s2():
    s, (Q, w, q) = q3_system()
    return f"毎秒{dec(fr(s[Q]))}cm³"
CHECKS[f"{E}-Q03-S02"] = {"method": "グラフの 2 点 (95 秒・50cm / 123 秒・60cm) と表面積の条件から Q・高い部分の幅・切り取りの高さを sympy の連立方程式で解く",
                          "compute": q3s2, "expect": "毎秒1000cm³", "official_value": "毎秒1000cm³"}


def q3s3():
    s, (Q, w, q) = q3_system()
    h1 = 60 - fr(s[q])
    t2 = (3600 - 50 * 40) * h1 / fr(s[Q])         # 深さ ① までは水の断面積 3600−2000
    return f"① {dec(h1)}, ② {dec(t2)}"
CHECKS[f"{E}-Q03-S03"] = {"method": "同じ連立方程式の解から ① = 60 − (切り取りの高さ)、② = (深さ ① までの水の量) ÷ 毎秒の量",
                          "compute": q3s3, "expect": "① 37.5, ② 60", "official_value": "① 37.5, ② 60",
                          "extra": [(lambda: (lambda s: 3600 * 50 - (2000 * (60 - fr(s[0][s[1][2]])) + fr(s[0][s[1][1]]) * 40 * (50 - (60 - fr(s[0][s[1][2]])))) == 95 * fr(s[0][s[1][0]]))(q3_system()),
                                     "求めた寸法で深さ 50cm のときの水の量が 95 秒分に一致 (グラフの点と整合)")]}


# ───────────── 大問 4: 100 個の分数を全部調べる ─────────────
LO, HI = F(27, 2026), F(75, 2024)


def inside():
    return [k for k in range(1, 101) if LO < F(k, 2025) < HI]
CHECKS[f"{E}-Q04-S01"] = {"method": "k/2025 (k=1〜100) を Fraction で 27/2026 と 75/2024 に厳密に比べて数える", "compute": lambda: len(inside())}
CHECKS[f"{E}-Q04-S02"] = {"method": "範囲内の k/2025 を約分した分子が 1 になるものを Fraction で数える", "compute": lambda: sum(1 for k in inside() if F(k, 2025).numerator == 1)}
CHECKS[f"{E}-Q04-S03"] = {"method": "分子が 1 になる分数の和を Fraction で厳密に足す", "compute": lambda: sum((F(k, 2025) for k in inside() if F(k, 2025).numerator == 1), F(0))}


# ───────────── 大問 5: 正十二角形を座標に置く ─────────────
def dodeca():
    return [(3 * sp.sin(sp.pi * k / 6), -3 * sp.cos(sp.pi * k / 6)) for k in range(12)]    # 外接円の半径 3 (向かい合う頂点の距離 6)、V0 = O (下の頂点)


def q5s1():
    V = dodeca()
    assert sp.simplify((V[3][0] - V[9][0]) - 6) == 0 and sp.simplify(V[3][1] - V[9][1]) == 0   # V3, V9 は中心を通る 6cm の線分の両端
    r2 = sp.simplify((V[3][0] - V[0][0]) ** 2 + (V[3][1] - V[0][1]) ** 2)                      # 円の半径² = |O V3|²
    return fr(r2 * sp.Rational(314, 100))
CHECKS[f"{E}-Q05-S01"] = {"method": "正十二角形の頂点座標 (外接円半径 3) から O と V3 の距離の 2 乗を求め 3.14 を掛ける", "compute": q5s1}


def q5s2():
    V = dodeca(); x = sp.Symbol("x")
    pts = [V[k] for k in range(3, 10)]                                           # 上半分 (y ≥ 0) の多角形 V3〜V9
    sh = sum(pts[i][0] * pts[(i + 1) % 7][1] - pts[(i + 1) % 7][0] * pts[i][1] for i in range(7)) / 2
    poly = sp.simplify(sp.Abs(sh))
    seg = sp.integrate(sp.sqrt(18 - x ** 2) - 3, (x, -3, 3))                     # 円 (中心 (0,-3)・半径²=18) の y ≥ 0 の部分 = 弓形
    seg = seg.subs(sp.pi, sp.Rational(314, 100))
    return fr(sp.nsimplify(poly - seg))


def arc_inside_polygon():
    """弓形の弧がすべて上半分の多角形の内側にある (斜線部分 = 多角形 − 弓形 になる) ことを高精度で確認。"""
    V = [(mpmath.mpf(3) * mpmath.sin(mpmath.pi * k / 6), -3 * mpmath.cos(mpmath.pi * k / 6)) for k in range(12)]
    poly = [V[k] for k in range(3, 10)]
    for i in range(-12, 13):
        x = mpmath.mpf(i) / 4
        P = (x, -3 + mpmath.sqrt(18 - x ** 2))
        for j in range(7):
            A_, B_ = poly[j], poly[(j + 1) % 7]
            if (B_[0] - A_[0]) * (P[1] - A_[1]) - (B_[1] - A_[1]) * (P[0] - A_[0]) < -mpmath.mpf(10) ** -40:
                return False
    return True
CHECKS[f"{E}-Q05-S02"] = {"method": "上半分の多角形の面積を靴ひも公式 (厳密) で、弓形の面積を sympy の積分で求めて引く", "compute": q5s2,
                          "extra": [(arc_inside_polygon, "弧が上半分の正十二角形の内側にある (斜線 = 多角形 − 弓形)")]}


# ───────────── 大問 6: 連立方程式 (時間の単位は『時間』) と秒単位の計算 ─────────────
def q6_D():
    t, u, D = sp.symbols("t u D", positive=True)             # 1 日目: 各速さの時間 t、2 日目: (あ)(い) は 2u・(う) は u、一周 D (km)
    day1, day2 = 7 * t + 9 * t + 12 * t, 7 * 2 * u + 9 * 2 * u + 12 * u
    sols = []
    for sign in (1, -1):                                       # 差の向きが分からないので両方を試し、正の解だけ残す
        for s in sp.solve([sp.Eq(day1, D), sp.Eq(day2, D), sp.Eq(sign * (5 * u - 3 * t), sp.Rational(108, 3600))], [t, u, D], dict=True):
            if all(v > 0 for v in s.values()):
                sols.append(s)
    assert len(sols) == 1
    return sols[0][D]
CHECKS[f"{E}-Q06-S01"] = {"method": "1 日目・2 日目の時間と一周の関係を sympy の連立方程式にし、時間差 1 分 48 秒 (=108/3600 時間) で解く (差の向きは両方試す)", "compute": lambda: fr(q6_D())}


def q6s2():
    D_m = fr(q6_D()) * 1000                                    # メートル
    secs = sum((D_m / 3) / (F(v * 1000, 3600)) for v in (7, 9, 12))   # 3 日目: 道のりを 3 等分し、秒速 (m/s) で割って秒数を足す
    assert secs.denominator == 1
    m, s = divmod(int(secs), 60)
    return f"{m}分{s}秒"
CHECKS[f"{E}-Q06-S02"] = {"method": "一周をメートルに直し、3 等分した道のりを秒速で割って秒数で足す (主解法の分・小数計算とは別経路)", "compute": q6s2,
                          "expect": "31分10秒", "official_value": "31分10秒"}


# ───────────── 大問 7: 食塩水を濃度 a, c と量の差 dl の連立方程式で ─────────────
x_, y_, z_, dl, a_, c_ = sp.symbols("x y z dl a c")


def harukos_amounts():
    amt = sp.solve([sp.Eq(x_ - y_, dl), sp.Eq(y_ - z_, dl), sp.Eq(x_ + y_ + z_, 300)], [x_, y_, z_], dict=True)[0]   # A,B,C の量 (差が等しく合計 300)
    return amt[x_], amt[y_], amt[z_]


def conc(xa, xb, xc):
    """A, B, C を xa, xb, xc (g) 混ぜた食塩水の濃度 (%)。A の濃度 a、B は a+3、C は c。"""
    return (xa * a_ + xb * (a_ + 3) + xc * c_) / 300


def q7s1():
    A_, B_, C_ = harukos_amounts()
    eq = sp.Eq(conc(B_, A_, C_) - conc(A_, B_, C_), sp.Rational(1, 5))            # 夏子さん: A と B の量を入れかえると 0.2% 高い
    sol = sp.solve(eq, dl)
    assert len(sol) == 1
    return fr(C_.subs(dl, sol[0]))
CHECKS[f"{E}-Q07-S01"] = {"method": "春子さんの量を差 dl で表し、A と B を入れかえた濃度差 0.2% の方程式を sympy で解く (濃度 a, c は式に残したまま消える)", "compute": q7s1}


def q7s2():
    A_, B_, C_ = harukos_amounts()
    dl_val = sp.solve(sp.Eq(conc(B_, A_, C_) - conc(A_, B_, C_), sp.Rational(1, 5)), dl)[0]
    eq = sp.Eq((conc(A_, C_, B_) - conc(A_, B_, C_)).subs(dl, dl_val), sp.Rational(2, 5))   # 秋子さん: B と C の量を入れかえると 0.4% 高い
    c_sol = sp.solve(eq, c_)
    assert len(c_sol) == 1
    return fr(sp.simplify(c_sol[0] - (a_ + 3)))                                    # C の濃度 − B の濃度
CHECKS[f"{E}-Q07-S02"] = {"method": "dl を (1) の方程式から求め、B と C を入れかえた濃度差 0.4% の方程式を c について解いて c − (a+3) を計算", "compute": q7s2}


def q7s3():
    A_, B_, C_ = harukos_amounts()
    D_conc = conc(A_, B_, C_)
    N = conc(B_, A_, C_) - D_conc - sp.Rational(1, 5)                              # 夏子さん
    K = conc(A_, C_, B_) - D_conc - sp.Rational(2, 5)                              # 秋子さん
    salt_K = A_ * a_ + C_ * (a_ + 3) + B_ * c_                                    # 秋子さんの食塩水の食塩 (g×%)
    W = salt_K - D_conc * (300 + sp.Rational(75, 4))                               # 水 18.75g を加えると D と同じ濃度
    sols = sp.solve([N, K, W], [dl, a_, c_], dict=True)
    assert len(sols) == 1
    s = sols[0]
    assert s[c_] > s[a_] + 3 and D_conc.subs(s) > s[a_] + 3                         # C は B より濃く、D は B より濃い
    return fr(s[c_])
CHECKS[f"{E}-Q07-S03"] = {"method": "夏子・秋子・水 18.75g の 3 条件を連立方程式 (未知数 dl, a, c) にして sympy で解く", "compute": q7s3}
