#include<bits/stdc++.h>
using namespace std;
const int p = 7, N = 1 << p, L = (N - 2) / p;
int SetPlus(int S, int a){
	int T = 0;
	for (int i = 0;i < p;++i)
		if (S >> i & 1)
			T |= 1 << ((i + a) % p);
	return T;
}
int Track[L][p];
int vis[N];
void IniT(){
	puts ("INIT START");
	memset(vis, -1, sizeof(vis));
	int cnt = 0;
	for (int S = 1; S < N - 1;++S){
		if (vis[S] == -1){
			for (int a = 0;a < p;++a){
				Track[cnt][a] = SetPlus(S, a);
				vis[Track[cnt][a]] = cnt;
			}
			++cnt;
		}
	}
	puts ("INIT FINISH");
}
int c, choose[L], ans = 0, tans = 0;
bool check(int dep){
	for (int pre = 0;pre < dep;++pre){
		int S = Track[pre][choose[pre]], T = Track[dep][choose[dep]], U = Track[vis[S & T]][choose[vis[S & T]]];
		if ((S & T) ^ U) return 0;
	}
	return 1;
}
void dfs(int dep){
	if (dep == L){
		++ans;
		++tans;
		return ;
	}
	int &a = choose[dep];
	for (a = 0;a < p;++a)
		if (Track[dep][a] >> c & 1 && check(dep))
			dfs(dep + 1);
}
int main(){
	IniT();
	for (c = 0;c < p;++c){
		printf ("Trying shift = %d\n", c);
		tans = 0;
		dfs(0);
		printf ("There are %d answers in this case\n", tans);
	}
	printf ("There are %d answers\n", ans);
	return 0;
}