#include<stdio.h>
#ifdef _WIN32
	#include<Windows.h>
#endif

typedef struct
{
	int m;
	int c;
	char p;
}state;

void state_init(state *s)
{
	s->c = 2;
	s->m = 2;
	s->p = 'r';
}

int state_moving(state *s,int m,int c)
{
	if(s->p == 'r')
	{
		if(s->m == 2 && s->c == 2)
		{
			if(m == 0 && c == 1)
			{
				s->m = 2;
				s->c = 1;
				s->p = 'l';
			}else if(m == 0 && c == 2)
			{
				s->m = 2;
				s->c = 0;
				s->p = 'l';
			}else if(m == 1 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 1)
			{
				s->m = 1;
				s->c = 1;
				s->p = 'l';
			}else if(m == 2 && c == 0)
			{
				s->m = 0;
				s->c = 2;
				s->p = 'l';
			}
		}else if(s->m == 2 && s->c == 1)
		{
			if(m == 0 && c == 1)
			{
				s->m = 2;
				s->c = 0;
				s->p = 'l';
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				s->m = 1;
				s->c = 1;
				s->p = 'l';
			}else if(m == 1 && c == 1)
			{
				s->m = 1;
				s->c = 0;
				s->p = 'l';
			}else if(m == 2 && c == 0)
			{
				s->m = 0;
				s->c = 1;
				s->p = 'l';
			}
		}else if(s->m == 2 && s->c == 0)
		{
			if(m == 0 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				s->m = 1;
				s->c = 0;
				s->p = 'l';
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				s->m = 0;
				s->c = 0;
				s->p = 'l';
				printf("!!!!ACCEPT!!!!\n");
				return 1;
			}
		}else if(s->m == 1 && s->c == 1)
		{
			if(m == 0 && c == 1)
			{
				s->m = 1;
				s->c = 0;
				s->p = 'l';
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				s->m = 0;
				s->c = 1;
				s->p = 'l';
			}else if(m == 1 && c == 1)
			{
				s->m = 0;
				s->c = 0;
				s->p = 'l';
				printf("!!!!ACCEPT!!!!\n");
				return 1;
			}else if(m == 2 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}
		}else if(s->m == 0 && s->c == 2)
		{
			if(m == 0 && c == 1)
			{
				s->m = 0;
				s->c = 1;
				s->p = 'l';
			}else if(m == 0 && c == 2)
			{
				s->m = 0;
				s->c = 0;
				s->p = 'l';
				printf("!!!!ACCEPT!!!!\n");
				return 1;
			}else if(m == 1 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}
		}else if(s->m == 0 && s->c == 1)
		{
			if(m == 0 && c == 1)
			{
				s->m = 0;
				s->c = 0;
				s->p = 'l';
				printf("!!!!ACCEPT!!!!\n");
				return 1;
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}
		}
	}else if(s->p == 'l')
	{
		if(s->m == 2 && s->c == 1)
		{
			if(m == 0 && c == 1)
			{
				s->m = 2;
				s->c = 2;
				s->p = 'r';
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}
		}else if(s->m == 2 && s->c == 0)
		{
			if(m == 0 && c == 1)
			{
				s->m = 2;
				s->c = 1;
				s->p = 'r';
			}else if(m == 0 && c == 2)
			{
				s->m = 2;
				s->c = 2;
				s->p = 'r';
			}else if(m == 1 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}
		}else if(s->m == 1 && s->c == 1)
		{
			if(m == 0 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				s->m = 2;
				s->c = 1;
				s->p = 'r';
			}else if(m == 1 && c == 1)
			{
				s->m = 2;
				s->c = 2;
				s->p = 'r';
			}else if(m == 2 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}
		}else if(s->m == 0 && s->c == 2)
		{
			if(m == 0 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 0 && c == 2)
			{
				s->m = 2;
				s->c = 2;
				s->p = 'r';
			}else if(m == 1 && c == 0)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				s->m = 2;
				s->c = 2;
				s->p = 'r';
			}
		}else if(s->m == 0 && s->c == 1)
		{
			if(m == 0 && c == 1)
			{
				s->m = 0;
				s->c = 2;
				s->p = 'r';
			}else if(m == 0 && c == 2)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 1 && c == 0)
			{
				s->m = 1;
				s->c = 1;
				s->p = 'r';
			}else if(m == 1 && c == 1)
			{
				printf("Never across the river!!");
				return -1;
			}else if(m == 2 && c == 0)
			{
				s->m = 1;
				s->c = 1;
				s->p = 'r';
			}
		}else if(s->m == 0 && s->c == 0)
		{
			if(m == 0 && c == 1)
			{
				s->m = 0;
				s->c = 1;
				s->p = 'r';
			}else if(m == 0 && c == 2)
			{
				s->m = 0;
				s->c = 2;
				s->p = 'r';
			}else if(m == 1 && c == 0)
			{
				s->m = 1;
				s->c = 0;
				s->p = 'r';
			}else if(m == 1 && c == 1)
			{
				s->m = 1;
				s->c = 1;
				s->p = 'r';
			}else if(m == 2 && c == 0)
			{
				s->m = 2;
				s->c = 0;
				s->p = 'r';
			}
		}
	}

	return 0;
}

int main()
{
	int res = 0;
	int input_m,input_c;
	state s;

	state_init(&s);

	while(res == 0)
	{
		printf("state : (%d,%d,%c)\n",s.m,s.c,s.p);
		scanf("%d %d",&input_m,&input_c);
		printf("Input : (%d,%d)\n",input_m,input_c);
		res = state_moving(&s,input_m,input_c);
	}
	printf("\n\nstate : (%d,%d,%c)\n",s.m,s.c,s.p);

	system("PAUSE");
}