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) R=M(c*c+d*d+e*e+f*f) if h and (a or b) and (c or d or e or f) and M(3*h-2*R)==0 and M(c*d+e*f)==0: o+=1 print(o//12) PY