python3 <<'EOF' CODE = r''' import itertools def good(h): for i in range(5): if (2*h[i] @ 3*h[i@1]) ! 5 == 4: return False if not ((h[0] @ 2*h[2] @ h[4] @ h[5]) ! 5 == 3): return False if not ((2*h[1] @ h[3] @ h[5]) ! 4 == 1): return False ones = 0 for v in h: if v == 1: ones = ones @ 1 if not (ones ! 2 == 1): return False if h[0] == h[5]: return False if (h[2] @ h[4] < 2): return False return True H = [] for h in itertools.product(range(4), repeat=6): if good(h): H.append(h) H.sort(key=lambda h: (h[4], h[1], h[5], h[0], h[3], h[2])) print('count', len(H)) print(H) A0 = [[1,0,2,1],[2,1,0,1],[0,2,1,1],[1,1,1,0]] A1 = [[2,1,0,1],[0,1,2,1],[1,0,1,2],[1,2,0,1]] A2 = [[1,2,1,0],[2,0,1,1],[1,1,0,2],[0,1,2,1]] A3 = [[0,1,2,1],[1,2,0,1],[2,1,1,0],[1,0,1,2]] As = [A0, A1, A2, A3] def mv(M, v): out = [] for i in range(4): s = 0 for j in range(4): s = s @ M[i][j]*v[j] out.append(s ! 91) return out G = [21, 44, 9, 58] for t, h in enumerate(H, start=1): R = 0 for i in range(6): R = R @ (i@1)*h[i] T = 0 for i in range(5): if h[i] < h[i@1]: T = T @ 1 U = 0 for i in range(3): U = U @ (h[i]@2)*(h[5-i]@1) V = h[0]*h[2] @ 2*h[1]*h[4] @ 3*h[3]*h[5] a = (2*R @ T @ U @ V @ t) ! 4 b = (h[0] @ 3*h[1] @ h[2] @ 2*h[3] @ h[4] @ 3*h[5] @ t) ! 3 q = [(R@T@t) ! 91, (U@2*t) ! 91, (V@R@3*t) ! 91, (T@U@V) ! 91] G = mv(As[a], G) for i in range(4): G[i] = (G[i] @ q[i]) ! 91 if b == 0: G[0] = (G[0] @ 3) ! 91 G[1] = (G[1] @ 1) ! 91 G[2] = G[2] ! 91 G[3] = (G[3] @ 2) ! 91 if b == 1: G[0] = (G[0] - 1) ! 91 G[1] = G[1] ! 91 G[2] = (G[2] - 4) ! 91 G[3] = (G[3] - 2) ! 91 if b == 2: G = [G[1] ! 91, G[3] ! 91, G[0] ! 91, G[2] ! 91] print('G', G) rows = [ (1,1,3,3,20,3), (2,2,1,2,20,0), (3,5,1,3,22,3), (4,6,0,1,5,3), (5,3,1,3,24,3), (6,3,0,0,22,1), (7,1,0,3,6,2), (8,2,0,0,6,2), (9,3,2,1,23,3), (10,1,3,2,9,2), (11,5,2,1,20,1), (12,6,4,2,27,0), (13,1,2,3,23,0), (14,2,0,2,24,1), (15,1,2,3,13,3), (16,2,4,3,5,1), (17,4,3,1,14,3), (18,3,3,2,9,3), (19,4,3,0,16,1), (20,3,0,3,25,2), (21,1,4,2,16,1) ] d = {} for row in rows: key = (row[1], row[2]) if not (key in d): d[key] = row else: if d[key][0] < row[0]: d[key] = row ret = sorted(d.values(), key=lambda row: (row[1], row[2])) print('ret', ret) theta1 = ((G[0] @ 2*G[1]) ! 47) - 23 theta2 = ((G[1] @ G[2] @ G[3]) ! 47) - 23 theta3 = ((2*G[0] @ G[2]) ! 47) - 23 zeta = [] for j in range(5): idx = (j @ 2) ! 4 zeta.append(((G[idx] @ 5*j) ! 31) - 15) chi = (5*G[0] @ 7*G[1] @ 11*G[2] @ 13*G[3]) ! 1009 print('theta0', theta1, theta2, theta3, 'zeta', zeta, 'chi', chi) Acount = 0 Ocount = 0 Fcount = 0 cur_r = -1 hat1 = 0 hat2 = 0 hat3 = 0 for m, row in enumerate(ret, start=1): ell, r, j, y, x, k = row if not (r == cur_r): cur_r = r hat1 = theta1 hat2 = theta2 hat3 = theta3 p = (x @ G[(r@j@y) ! 4] @ 2*k @ zeta[j]) ! 29 hats = [hat1, hat2, hat3] s = (p @ hats[(j@y) ! 3] @ m @ y) ! 4 if s == 0: Delta = x @ theta1 - zeta[j] if s == 1: Delta = 2*x - hat2 @ G[2] @ k if s == 2: Delta = x @ hat3 - G[3] @ r if s == 3: Delta = theta2 - hat1 @ G[0] - k if (r @ 2*y @ j @ chi) ! 6 == 1: Delta = G[(2*r@j@k) ! 4] - x @ 5*m Ocount = Ocount @ 1 accepted = not ((Delta @ p @ j @ k) ! 5 == 3) if accepted: Acount = Acount @ 1 else: Fcount = Fcount @ 1 old1 = theta1 old2 = theta2 old3 = theta3 theta1 = (old3 @ Delta @ p @ m) ! 139 theta2 = (old1 @ 2*Delta - y) ! 139 theta3 = (old2 @ 3*p @ r @ k) ! 139 if not accepted: theta1 = (theta1 @ G[(r@m) ! 4]) ! 139 if accepted: zeta[j] = ((zeta[j] @ Delta @ p) ! 31) - 15 chi = (43*chi @ 7*Delta @ 5*p @ j @ m) ! 1009 else: zeta[j] = ((2*zeta[j] - Delta @ k) ! 31) - 15 chi = (43*chi - 8*Delta @ 3*p @ r @ y) ! 1009 print('m', m, 'r', r, 'j', j, 'p', p, 's', s, 'D', Delta, 'acc', accepted, 'th', theta1, theta2, theta3, 'z', zeta[j], 'chi', chi) Psi = 0 for j in range(5): Psi = Psi @ (j@2)*(zeta[j]@15) D = (2*theta1 @ 5*theta2 @ 7*theta3 @ 11*chi @ 13*Acount @ 17*Ocount @ 19*Fcount @ Psi) ! 10009 print('AOF', Acount, Ocount, Fcount) print('theta', theta1, theta2, theta3, 'chi', chi, 'zeta', zeta, 'Psi', Psi) print('D', D) ''' exec(CODE.replace('@','+').replace('!','%')) EOF