#define	hval(x)	(x % 15)

char a[15];

main()
{
	char x[8];
	int i;
lp:
	write(1,"> ", 2);
	x[read(0, x, 8)-1] = 0;
	if(x[0] == 'p'){
		for(i=0; i < 16; i++)printf("%3d", a[i]);
		printf("\n");
		goto lp;
	} else
	if(x[0] == 'a')add(atoi(x+1));
	else del(atoi(x+1));
	goto lp;
}

add(n)
{
	int h;
	h = hval(n);
lp:
	if(a[h]){
		printf("Hit %d\n", h);
		h++;
		if(h >= 15)h=0;
		goto lp;
	}
	a[h] = n;
}

del(n)
{
	int h;
	int ent, nent;
	h = hval(n);
lp2:
	while(a[h] != n){
		h++;
		if(h >= 15)h=0;
		if(a[h] == 0)return;
		goto lp2;
	}
	ent = h;
	nent = ent+1;
	if(nent >= 15)nent = 0;

lp:
	a[ent] = 0;
	if(a[nent] == 0)return;
	ent = hval(a[nent]);
	while(a[ent]){
		if(++ent >= 15)ent=0;
	}
	a[ent] = a[nent];
	ent=nent;
	if(++nent>=15)nent=0;
	goto lp;
}
