a = {1, 1, 1, 1, 1}
d = {{1, 2}, {1, 1}}

Block[{i}, 
 
      For[i = 1, i ≤ Length[a], i++, 
        a[[i]] = i]
 ]

Print[a]

Permut[i_] := 
      Block[{ok = 1, j, z, 
          k = i + 1}, 
If[
            i ≤ Length[a], 
For[j = 1, 
              j ≤ Length[a], j++, 
For[
                z = 1, z ≤ 
                  i - 1, z++, 
If[
                    a[[z]] == j, 
                    ok = 0, ];
]; 
If[
                ok, a[[i]] = j; Permut[k], ]; 
ok = 
                1;
], Rachunaj[Length[a]]; 
            Print[a];
];
]

Rachunaj[n_] := 
      Block[{i, j, paran, 
          Suma = 1}, 
For[i = 1, 
            i ≤ n - 1, i++, 
 
            Count = 0; 
For[j = i + 1, 
                j ≤ 
                  n, j++, 
If[
                    a[[i]] > 
                      a[[j]], Count++, ];]
If[
                Mod[Count, 2] == 0, paran = 1, 
                paran = 0];
]
For[i = 1, 
            i ≤ 
              n, i++, 
Suma *= d[i][
                a[[i]]]]; 
   If[paran, 
          Ukupno += Suma, Ukupno -= Suma];
]

Permut[1]

Print[a]