#include <stdio.h>
#include <glib.h>
#define A 16
#define B 16
#define N 16
gboolean equal(char *p1, char *p2) {
int i;
for (i = 0; i<N; i+=1) {
if (p1[i]!=p2[i]) {
return 0;
}
}
return 1;
}
int main() {
int i, j, k, p, pi;
char POZA[N+1], Z[B+1], *r;
char *new_poza[8];
int VOS[B+A-1], ZAK[B+A-1];
GHashTable *results = g_hash_table_new(g_str_hash, equal);
POZA[N] = 0;
for (k = 0; k<=B; k+=1) { Z[k] = k+1; }
for (k = 1-A; k<B; k+=1) { VOS[k+A-1] = 0; }
for (k = 2; k<=B+A; k+=1) { ZAK[k-2] = 0; }
i = k = 0;
PER: i += 1; if (i>N) { goto ZAP; } p = 0;
BOK: j = p; p = Z[j]; if (p>N) { goto ZAD; }
PRV: if (VOS[p-i+A-1] || ZAK[p+i-2]) { goto BOK; }
PRP: VOS[p-i+A-1] = ZAK[p+i-2] = 1;
Z[j] = Z[p]; Z[p] = j; POZA[i-1] = p;
goto PER;
ZAP:
if (!(r = g_hash_table_lookup(results, POZA))) {
k += 1;
new_poza[0] = (char *)malloc(N+1);
new_poza[1] = (char *)malloc(N+1);
new_poza[2] = (char *)malloc(N+1);
new_poza[3] = (char *)malloc(N+1);
new_poza[4] = (char *)malloc(N+1);
new_poza[5] = (char *)malloc(N+1);
new_poza[6] = (char *)malloc(N+1);
new_poza[7] = (char *)malloc(N+1);
for (pi=0; pi<N; pi+=1) {
new_poza[0][pi] = POZA[pi];
new_poza[1][N-1-pi] = POZA[pi];
new_poza[2][pi] = N+1-POZA[pi];
new_poza[3][N-1-pi] = N+1-POZA[pi];
new_poza[4][POZA[pi]-1] = pi+1;
new_poza[5][N-POZA[pi]] = pi+1;
new_poza[6][POZA[pi]-1] = N-pi;
new_poza[7][N-POZA[pi]] = N-pi;
}
new_poza[0][N] = 0;
new_poza[1][N] = 0;
new_poza[2][N] = 0;
new_poza[3][N] = 0;
new_poza[4][N] = 0;
new_poza[5][N] = 0;
new_poza[6][N] = 0;
new_poza[7][N] = 0;
g_hash_table_insert(results, new_poza[0], new_poza[0]);
g_hash_table_insert(results, new_poza[1], new_poza[1]);
g_hash_table_insert(results, new_poza[2], new_poza[2]);
g_hash_table_insert(results, new_poza[3], new_poza[3]);
g_hash_table_insert(results, new_poza[4], new_poza[4]);
g_hash_table_insert(results, new_poza[5], new_poza[5]);
g_hash_table_insert(results, new_poza[6], new_poza[6]);
g_hash_table_insert(results, new_poza[7], new_poza[7]);
}
ZAD: i -= 1; if (i==0) { goto VSJO; }
VYP: p = POZA[i-1]; j = Z[p]; Z[p] = Z[j]; Z[j] = p;
VOS[p-i+A-1] = ZAK[p+i-2] = 0;
goto BOK;
VSJO:
printf("%d %d\n", g_hash_table_size(results), k);
return 0;
}