python3 - <<'PY' from itertools import product M=lambda x:x-7*(x//7) o=0 for a,b,c,d,e,f in product(range(7),repeat=6): h=M(a*a-a*b+b*b)