#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define BOWLS 40
#define ORANGES 9
int solutions = 0;
typedef char t_bowls[BOWLS];
typedef char t_distances[ORANGES][BOWLS];
void rec(int oranges, int pos, t_bowls i_bowls, t_distances i_distances)
{
int i, j;
t_bowls bowls;
t_distances distances;
if (pos >= BOWLS) return;
memcpy(bowls, i_bowls, sizeof(bowls));
memcpy(distances, i_distances, sizeof(distances));
rec(oranges, pos+1, bowls, distances);
bowls[pos] = 1;
oranges--;
for(i = 0, j = ORANGES; i < pos; i++) {
if (bowls[i]) {
int dist = pos - i; j--;
if (distances[oranges][dist] || distances[j][dist]) return;
distances[oranges][dist] = distances[j][dist] = 1;
}
}
if (!oranges) {
solutions++;
return;
}
rec(oranges, pos+1, bowls, distances);
}
int main()
{
static t_bowls bowls;
static t_distances distances;
rec(ORANGES, 0, bowls, distances);
printf("%d\n", solutions);
return 0;
}