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

enum {
	MINVAL = 0,
	MAXVAL = 500,
	NELEMS = MAXVAL - MINVAL + 1,
	NUMBERS = 5,
	ZERO_BASED = 1
};

struct node {
	int val;
	struct node *next;
};

struct node *new(int v, struct node *np)
{
	static struct node mem[NUMBERS];
	static int n;

	mem[n].val = v;
	mem[n].next = np;
	return mem + n++;
}

int main(void)
{
	static struct node *a[NELEMS];
	struct node *np;
	int i, r;

	for (i = 0; i < NUMBERS; i++) {
		printf(" %d", (r = rand() / (RAND_MAX / NELEMS)) + 1);
		a[r] = new(i, a[r]);
	}
	puts("");
	for (i = 0; i < NELEMS; i++)
		for (np = a[i]; np; np = np->next)
			printf(" %d", np->val + !ZERO_BASED);
	puts("");
	return 0;
}