Result1CN1:= [
    <[ -1, 1 ], 1, [
        <[ 2 ], 2>,
        <[ 3 ], 3>,
        <[ 5 ], 5>,
        <[ 7 ], 7>,
        <[ 13 ], 13>
    ]>,
    <[ -1, -1, 1 ], 5, [
        <[ 1, 0 ], 1>,
        <[ -2, 4 ], 20>,
        <[ 4, -6 ], 44>,
        <[ 2, -6 ], 44>
    ]>,
    <[ -2, 0, 1 ], 8, [
        <[ 1, 0 ], 1>,
        <[ -4, 1 ], 14>,
        <[ 4, 1 ], 14>,
        <[ 0, -3 ], 18>,
        <[ 0, -5 ], 50>
    ]>,
    <[ -3, 0, 1 ], 12, [
        <[ 1, 0 ], 1>,
        <[ -3, -1 ], 6>,
        <[ -1, -3 ], 26>,
        <[ -1, 3 ], 26>
    ]>,
    <[ -3, -1, 1 ], 13, [
        <[ 1, 0 ], 1>,
        <[ 0, 2 ], 12>,
        <[ -2, 2 ], 12>
    ]>,
    <[ -4, -1, 1 ], 17, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -5, -1, 1 ], 21, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -6, 0, 1 ], 24, [
        <[ 1, 0 ], 1>,
        <[ -12, 5 ], 6>
    ]>,
    <[ -7, 0, 1 ], 28, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -8, -1, 1 ], 33, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -15, 0, 1 ], 60, [
        <[ 1, 0 ], 1>
    ]>,
    <[ 1, -2, -1, 1 ], 49, [
        <[ -1, -2, 1 ], 7>,
        <[ 2, 0, 0 ], 8>,
        <[ -3, 1, 1 ], 13>,
        <[ -2, -2, 1 ], 13>,
        <[ 2, 1, -2 ], 13>,
        <[ -4, 1, 2 ], 29>,
        <[ -4, -1, 3 ], 29>,
        <[ -4, -2, 3 ], 29>,
        <[ 2, 3, -1 ], 43>,
        <[ 3, 2, -3 ], 43>,
        <[ 5, -1, -2 ], 43>
    ]>,
    <[ -1, -3, 0, 1 ], 81, [
        <[ 1, -1, 0 ], 3>,
        <[ -3, 0, 2 ], 19>,
        <[ 2, 1, -2 ], 19>,
        <[ -1, 2, 0 ], 19>,
        <[ 2, -2, -1 ], 37>,
        <[ -6, -1, 3 ], 37>,
        <[ 4, 3, -2 ], 37>
    ]>,
    <[ 1, -3, -1, 1 ], 148, [
        <[ 1, -1, 0 ], 2>,
        <[ -1, -1, 1 ], 5>,
        <[ 2, 2, -1 ], 13>
    ]>,
    <[ -1, -4, -1, 1 ], 169, [
        <[ 2, 1, -1 ], 5>,
        <[ -3, -2, 1 ], 5>,
        <[ -1, 1, 0 ], 5>,
        <[ 3, 0, -1 ], 13>
    ]>,
    <[ -1, -4, 0, 1 ], 229, [
        <[ 3, 1, -1 ], 4>
    ]>,
    <[ 2, -4, -1, 1 ], 316, [
        <[ 0, 1, 0 ], 2>
    ]>,
    <[ 1, -4, -1, 1 ], 321, [
        <[ 1, -1, 0 ], 3>
    ]>,
    <[ 1, 1, -3, -1, 1 ], 725, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 4, -4, -1, 1 ], 1125, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -1, -4, 0, 1 ], 1957, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 5, 0, -5, 0, 1 ], 2000, [
        <[ 1, 0, 0, 0 ], 1>,
        <[ -5, 2, 2, -1 ], 20>
    ]>,
    <[ 1, 0, -4, 0, 1 ], 2304, [
        <[ 1, 0, 0, 0 ], 1>,
        <[ 2, 7, -1, -2 ], 18>
    ]>,
    <[ 2, 1, -4, -1, 1 ], 2777, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -8, -7, 2, 1 ], 3600, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 2, -4, -6, 0, 1 ], 4352, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 4, -3, -2, 1 ], 4752, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -6, -7, 0, 1 ], 10512, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 3, -1, -5, 0, 1 ], 24217, [
        <[ -3, -2, 9, 1, -2 ], 5>
    ]>
];
Result1CN2:=
[
    <[ -1, 1 ], 1, [
        <[ 30 ], 30>,
        <[ 42 ], 42>,
        <[ 70 ], 70>,
        <[ 11 ], 11>,
        <[ 78 ], 78>,
        <[ 17 ], 17>,
        <[ 19 ], 19>
    ]>,
    <[ -1, -1, 1 ], 5, [
        <[ 6, 0 ], 36>,
        <[ -3, 6 ], 45>,
        <[ -8, 1 ], 55>,
        <[ 6, -9 ], 99>,
        <[ -7, -1 ], 55>,
        <[ 3, -9 ], 99>,
        <[ -9, -2 ], 95>,
        <[ -11, 2 ], 95>,
        <[ -6, 10 ], 124>,
        <[ 13, -1 ], 155>,
        <[ -4, 10 ], 124>,
        <[ 12, 1 ], 155>,
        <[ 12, 2 ], 164>,
        <[ 14, -2 ], 164>
    ]>,
    <[ -2, 0, 1 ], 8, [
        <[ -3, 6 ], 63>,
        <[ -3, -6 ], 63>,
        <[ 6, -1 ], 34>,
        <[ 6, 1 ], 34>,
        <[ 8, 1 ], 62>,
        <[ 8, -1 ], 62>
    ]>,
    <[ -3, 0, 1 ], 12, [
        <[ -3, 4 ], 39>,
        <[ 3, 4 ], 39>,
        <[ -5, -5 ], 50>
    ]>,
    <[ -3, -1, 1 ], 13, [
        <[ 3, 0 ], 9>,
        <[ -6, -1 ], 39>,
        <[ -7, 1 ], 39>
    ]>,
    <[ -4, -1, 1 ], 17, [
        <[ 2, 0 ], 4>,
        <[ 6, -3 ], 18>,
        <[ 3, 3 ], 18>,
        <[ -2, -3 ], 26>,
        <[ 5, 1 ], 26>,
        <[ -6, 1 ], 26>,
        <[ -5, 3 ], 26>
    ]>,
    <[ -5, -1, 1 ], 21, [
        <[ 1, 0 ], 1>,
        <[ -2, -2 ], 12>,
        <[ 4, 1 ], 15>,
        <[ 2, -2 ], 20>,
        <[ 5, 2 ], 15>,
        <[ 0, -2 ], 20>
    ]>,
    <[ -6, 0, 1 ], 24, [
        <[ 1, 0 ], 1>,
        <[ 3, -2 ], 15>,
        <[ 9, -4 ], 15>
    ]>,
    <[ -7, 0, 1 ], 28, [
        <[ 1, 0 ], 1>,
        <[ 13, 5 ], 6>,
        <[ 1, 1 ], 6>,
        <[ 7, 3 ], 14>
    ]>,
    <[ -7, -1, 1 ], 29, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -8, -1, 1 ], 33, [
        <[ 1, 0 ], 1>,
        <[ -1, -1 ], 6>,
        <[ -26, -11 ], 6>
    ]>,
    <[ -9, -1, 1 ], 37, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -10, 0, 1 ], 40, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -10, -1, 1 ], 41, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -11, 0, 1 ], 44, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -14, -1, 1 ], 57, [
        <[ 1, 0 ], 1>
    ]>,
    <[ -15, 0, 1 ], 60, [
        <[ -3, -1 ], 6>
    ]>,
    <[ -17, -1, 1 ], 69, [
        <[ 1, 0 ], 1>
    ]>,
    <[ 1, -2, -1, 1 ], 49, [
        <[ 3, 0, 0 ], 27>,
        <[ 4, 3, -2 ], 41>,
        <[ -4, 2, 1 ], 41>,
        <[ -3, -1, 3 ], 41>,
        <[ -6, 1, 3 ], 71>,
        <[ -4, -1, 0 ], 71>,
        <[ 6, 0, -1 ], 71>,
        <[ -4, -3, 4 ], 97>,
        <[ -7, 1, 3 ], 97>,
        <[ -2, -4, 1 ], 97>,
        <[ -5, -4, 2 ], 113>,
        <[ -8, 1, 3 ], 113>,
        <[ -3, -4, 1 ], 113>,
        <[ 6, -2, -3 ], 127>,
        <[ 7, 3, -5 ], 127>,
        <[ -2, -5, 2 ], 127>
    ]>,
    <[ -1, -3, 0, 1 ], 81, [
        <[ 2, 0, 0 ], 8>,
        <[ -3, -2, 1 ], 17>,
        <[ -3, -1, 2 ], 17>,
        <[ 3, -1, -1 ], 17>,
        <[ -2, 3, 0 ], 73>,
        <[ -8, -3, 3 ], 73>,
        <[ -4, 0, 3 ], 73>
    ]>,
    <[ 1, -3, -1, 1 ], 148, [
        <[ 1, 2, 0 ], 17>,
        <[ -4, -1, 2 ], 25>
    ]>,
    <[ -1, -4, -1, 1 ], 169, [
        <[ 2, 0, 0 ], 8>
    ]>,
    <[ -1, -4, 0, 1 ], 229, [
        <[ -1, -1, 0 ], 2>,
        <[ -2, 0, 1 ], 7>,
        <[ -2, -2, 1 ], 13>
    ]>,
    <[ 3, -4, -1, 1 ], 257, [
        <[ 0, -1, 0 ], 3>,
        <[ -1, -1, 0 ], 5>,
        <[ 2, 0, -1 ], 7>,
        <[ -4, -1, 1 ], 9>
    ]>,
    <[ 2, -4, -1, 1 ], 316, [
        <[ -1, 1, 0 ], 2>
    ]>,
    <[ 1, -4, -1, 1 ], 321, [
        <[ -1, -1, 0 ], 3>,
        <[ 2, 0, -1 ], 7>
    ]>,
    <[ 7, -6, -1, 1 ], 361, [
        <[ 0, 1, 0 ], 7>,
        <[ 5, -1, -1 ], 7>,
        <[ 4, 0, -1 ], 7>
    ]>,
    <[ -1, -5, -1, 1 ], 404, [
        <[ 1, 1, 0 ], 2>
    ]>,
    <[ 4, -5, -1, 1 ], 469, [
        <[ -3, 1, 1 ], 4>
    ]>,
    <[ -2, -6, -1, 1 ], 568, [
        <[ 0, -1, 0 ], 2>
    ]>,
    <[ 1, 4, -4, -1, 1 ], 1125, [
        <[ 1, 0, 0, 0 ], 1>,
        <[ 1, -5, 0, 1 ], 45>,
        <[ -6, -6, 2, 2 ], 80>
    ]>,
    <[ 4, 0, -6, 0, 1 ], 1600, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -1, -4, 0, 1 ], 1957, [
        <[ 2, -2, -1, 1 ], 21>
    ]>,
    <[ 2, 0, -4, 0, 1 ], 2048, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 4, 2, -5, -1, 1 ], 2225, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 5, 5, -4, -2, 1 ], 2525, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 2, -3, -2, 1 ], 2624, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 2, -4, -1, 1 ], 3981, [
        <[ 1, 0, 0, 0 ], 1>,
        <[ 0, -4, 0, 1 ], 15>
    ]>,
    <[ 1, -1, -5, -1, 1 ], 4205, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 2, -4, -6, 0, 1 ], 4352, [
        <[ -4, 3, 2, -1 ], 14>,
        <[ 2, 1, -1, 0 ], 14>
    ]>,
    <[ 1, 4, -3, -2, 1 ], 4752, [
        <[ -1, 2, 2, -1 ], 12>
    ]>,
    <[ 11, 7, -6, -2, 1 ], 5125, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 11, 9, -9, -1, 1 ], 6125, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -1, -5, 0, 1 ], 6809, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 0, -5, 0, 1 ], 7056, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 2, -4, -2, 1 ], 7488, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 3, 4, -5, -1, 1 ], 7537, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ 3, -3, -6, 0, 1 ], 9909, [
        <[ 1, 0, 0, 0 ], 1>
    ]>,
    <[ -1, 3, 3, -4, -1, 1 ], 14641, [
        <[ -1, -1, 3, 1, -1 ], 11>,
        <[ -1, 0, -3, 0, 1 ], 23>,
        <[ 2, -1, -3, 0, 1 ], 23>,
        <[ -1, -1, 4, 0, -1 ], 23>,
        <[ -3, -1, 1, 0, 0 ], 23>,
        <[ -1, -4, 0, 1, 0 ], 23>
    ]>,
    <[ 1, 3, -1, -5, 0, 1 ], 24217, [
        <[ -2, 0, 1, 0, 0 ], 17>,
        <[ 4, 6, -9, -2, 2 ], 17>
    ]>,
    <[ -1, 1, 5, -3, -2, 1 ], 36497, [
        <[ -1, -4, 3, 2, -1 ], 3>,
        <[ 2, -2, -2, 1, 0 ], 13>
    ]>,
    <[ -1, 4, 0, -5, 0, 1 ], 38569, [
        <[ 2, 0, -1, 0, 0 ], 7>,
        <[ 4, -4, -9, 1, 2 ], 13>
    ]>,
    <[ -1, -2, 7, 2, -7, -1, 1 ], 300125, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ -1, -3, 6, 4, -5, -1, 1 ], 371293, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ -1, -2, 4, 5, -4, -2, 1 ], 434581, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -8, 8, 6, -6, -1, 1 ], 453789, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -5, 2, 8, -4, -2, 1 ], 485125, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ -1, -2, 5, 4, -5, -1, 1 ], 592661, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ 1, -6, 3, 10, -3, -3, 1 ], 1397493, [
        <[ 1, 0, 0, 0, 0, 0 ], 1>
    ]>,
    <[ 1, 0, -8, 0, 14, 0, -7, 0, 1 ], 324000000, [
        <[ 1, 0, 0, 0, 0, 0, 0, 0 ], 1>
    ]>
];

function ReadEntry(S)
  K:= NumberField(Polynomial(S[1]));
  L:= [];
  for s in S[3] do
    if Type(K) eq FldRat then
      E:= QuaternionAlgebra(Integers() ! s[1]);
    else
      E:= QuaternionAlgebra( Integers(K) * (K ! s[1]), InfinitePlaces(K) );
    end if;
    Append(~L, E);
  end for;
  return L;
end function;

function Lattices(M)
  K:= BaseField(Algebra(M));
  N, h:= NarrowClassGroup(K);
  S:= {@ n: n in N @};
  U, g:= UnitGroup(K);
  if Type(K) eq FldRat then 
    T:= sub< U | >;
  else
    P:= Subsets({u @ g : u in Generators(U)});
    x:= [ u : p in P | IsTotallyPositive(u) where u:= &*p ];
    T:= sub< U | 2*U, [u @@ g : u in x] >;
  end if;

  L:= LeftIdealClasses(M);
  C:= [ {* Integers() | *}^^#S ];
  for j in [1..#L] do
    I:= L[j];
    i:= #S eq 1 select 1 else Index(S, Norm(I) @@ h);
    assert i gt 0;
    UO, hO:= UnitGroup(RightOrder(I));
    idx:= #T eq 1 select 1 else #quo< T | 2*U, [ Norm(u @ hO) @@ g  : u in Generators(UO) ] >;
    Include(~C[i], j^^idx);
  end for;
  assert forall{c: c in C | not IsEmpty(c) };
  CN:= Sort(Setseq({ #c: c in C }));
  return &cat [ [ < L[Rep(c)], i > : c in C | #c eq i ] : i in CN ];
end function;
