s = vector(500)
a = vector(100)	\\ circular buffer
cat(x,y) = x*2^#binary(y)+y

{
	for (n=1, 10 000,
		print (n " " a[1+n%#a] = if (n==1, 1, s[a[1+(n-1)%#a]]));
		c = 0;
		forstep (k=n, 1, -1,
			c=cat(a[1+k%#a], c);
			if (c>#s, break, s[c]++);
		);
	);
}

quit