#!/usr/bin/env python3
"""Exact audits for the strict-shell variants left by the fifth referee."""

D = 565
CROSS = 552
R2_NUM = 300 * D
L = 4535


def norm_num(m: int, n: int) -> int:
    return D * m * m + D * n * n + CROSS * m * n


def tri_norm(m: int, n: int) -> int:
    return m * m + m * n + n * n


obs = [
    (m, n)
    for m in range(-50, 51)
    for n in range(-50, 51)
    if (m, n) != (0, 0) and norm_num(m, n) < R2_NUM
]
tri_closed = [
    (m, n)
    for m in range(-50, 51)
    for n in range(-50, 51)
    if (m, n) != (0, 0) and tri_norm(m, n) <= 300
]
tri_strict = [
    (m, n)
    for m in range(-50, 51)
    for n in range(-50, 51)
    if (m, n) != (0, 0) and tri_norm(m, n) < 300
]

assert 276**2 + 493**2 == 565**2
assert len(obs) == 1078
assert len(tri_closed) == 1074
assert len(tri_strict) == 1068
assert all(abs(m) <= 19 and abs(n) <= 19 for m, n in obs)
assert all(abs(m) <= 20 and abs(n) <= 20 for m, n in tri_closed)
assert min(norm_num(m, n) for m in range(-50, 51) for n in range(-50, 51) if (m, n) != (0, 0)) == D

sum_l1 = sum(abs(m) + abs(n) for m, n in obs)
sum_prod = sum(abs(m) * abs(n) for m, n in obs)
assert sum_l1 == 18_156
assert sum_prod == 75_856


def directed(side: int) -> int:
    return sum((side - abs(m)) * (side - abs(n)) for m, n in obs)


assert all(directed(side) <= 1074 * side * side for side in range(20, L))
assert directed(L) == 22_088_128_946
assert 1074 * L * L == 22_088_125_650
assert directed(L) - 1074 * L * L == 3_296
assert directed(L) % 2 == 0
assert directed(L) // 2 == 11_044_064_473
assert 537 * L * L == 11_044_062_825
assert directed(L) // 2 - 537 * L * L == 1_648

print(f"strict oblique offsets below squared radius 300: {len(obs)}")
print(f"closed triangular comparison through 300: {len(tri_closed)}")
print(f"strict triangular count below 300: {len(tri_strict)}")
print(f"sum |m|+|n|: {sum_l1}")
print(f"sum |m||n|: {sum_prod}")
print(f"first winning integer side: {L}")
print(f"points: {L*L}")
print(f"directed strict pairs: {directed(L)}")
print(f"closed-triangular directed allowance: {1074*L*L}")
print(f"directed excess: {directed(L)-1074*L*L}")
print(f"unordered strict pairs: {directed(L)//2}")
print(f"unordered allowance: {537*L*L}")
print(f"unordered excess: {directed(L)//2-537*L*L}")
