#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#define BOX_NUM 2
#define HISTORY_NUM_MAX 1024


typedef struct
{
	int capacity, volume;
}box_t;


typedef struct
{
	box_t box[BOX_NUM];
	int times;
	int parent;
}state_t;


state_t history[HISTORY_NUM_MAX];
int history_num=0;


void history_clear(void)
{
	memset(history, -1, sizeof(history));
	history_num=0;
}


int history_search(state_t *p)
{
	int i;

	for(i=0;i<history_num;i++)
	{
		if(memcmp(&history[i], p, sizeof(history[i].box))==0) return i;
	}
	return -1;
}


void history_add(state_t *p, int parent)
{
	if(history_search(p)>=0) return;

	if(history_num>=HISTORY_NUM_MAX)
	{
		printf("\nERROR : overflow\n");
		exit(1);
	}
	p->parent=parent;
	if(parent>=0)
	{
		p->times=history[parent].times+1;
	}
	else
	{
		p->times=0;
	}
	history[history_num++]=*p;
}


void box_fill(box_t *p)
{
	p->volume=p->capacity;
}


void box_empty(box_t *p)
{
	p->volume=0;
}


void box2box(box_t *to, box_t *from)
{
	int volume1, volume2, move_volume;

	volume1=from->volume;
	volume2=to->capacity-to->volume;

	if(volume1<volume2) move_volume=volume1;
	else move_volume=volume2;

	to->volume+=move_volume;
	from->volume-=move_volume;
}


int solve(void)
{
	state_t work;
	int i, j, k;

	for(i=0;i<history_num;i++)
	{
		if(history[i].box[0].volume==2 && history[i].box[1].volume==0) return i;
		for(j=0;j<BOX_NUM;j++)
		{
			work=history[i]; box_fill(&(work.box[j])); history_add(&work, i);
			work=history[i]; box_empty(&(work.box[j])); history_add(&work, i);

			for(k=0;k<BOX_NUM;k++)
			{
				if(j==k) continue;
				work=history[i]; box2box(&(work.box[j]), &(work.box[k])); history_add(&work, i);
			}
		}
	}
}


void state_print(state_t *p)
{
	int i, goukei=0;

	for(i=0;i<BOX_NUM;i++)
	{
		goukei+=p->box[i].volume;
		printf("%dL=%d,", p->box[i].capacity, p->box[i].volume);
	}
	printf("Goukei=%d\n", goukei);
}


void result_print(int index)
{
	if(index<0) return;

	result_print(history[index].parent);
	state_print(&history[index]);
}


int main(void)
{
	state_t initial={{{4,0},{3,0}}};
	int i, result;

	history_clear();
	history_add(&initial, -1);
	result=solve();

	result_print(result);
	return 0;
}
