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

#ifndef max
	#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
#endif

#define STOP 5000


inline uint32_t zend_inline_hash_func(const char *arKey, uint32_t nKeyLength)
{
        register uint32_t hash = 5381;

        /* variant with the hash unrolled eight times */
        for (; nKeyLength >= 8; nKeyLength -= 8) {
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
                hash = ((hash << 5) + hash) + *arKey++;
        }
        switch (nKeyLength) {
                case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
                case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
                case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
                case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
                case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
                case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
                case 1: hash = ((hash << 5) + hash) + *arKey++; break;
                case 0: break;
        }
        return hash;
}

struct ll {
	char str[16];
	struct ll *next;
};

#define BSZ 65536

struct ll *bckt[BSZ];
uint32_t bcktsz[BSZ];

char alphabet[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTUVWXYZ01234567890";



int main()
{
	int ln,i,strl;
	uint32_t cmax=0;
	uint32_t mask,hash;
	int cstr[16];
	char stro[16];
	struct ll *tmp;

	memset(&bckt, 0, sizeof(bckt));
	memset(&bcktsz, 0, sizeof(bcktsz));

	memset(&stro, 0, sizeof(stro));

	ln=strlen(alphabet);
	mask=0xffff;

	for(strl=1;strl<17;strl++) {
		memset(&cstr, 0, sizeof(cstr));
//		printf("%d %d\n", strl, cmax);
		while(cstr[strl]==0) {
		//increase
			for (i=0;i<strl;i++) stro[i]=alphabet[cstr[i]];
			hash = zend_inline_hash_func(stro, strl) & mask;
		// do insert

			bcktsz[hash]++;
///			printf("%s %X %d %d\n",stro, hash, bcktsz[hash], cmax);
			cmax=max(cmax, bcktsz[hash]);
			if (bckt[hash]==NULL) {
				bckt[hash]=(struct ll *)malloc(sizeof(struct ll));
				bckt[hash]->next=NULL;
				memcpy(bckt[hash]->str, stro, strl+1);
			} else {
				tmp=bckt[hash];		
				bckt[hash]=(struct ll *)malloc(sizeof(struct ll));
				bckt[hash]->next=tmp;
				memcpy(bckt[hash]->str, stro, strl+1);
			}
			if (cmax>STOP) {
				for (i=0;i<BSZ;i++)
					if (bcktsz[i]==cmax) break;
		//		printf("FOUND %d %d\n", i, cmax);
				tmp=bckt[i];
				for (;tmp!=NULL; tmp=tmp->next) {
					printf("%s\n", tmp->str);
				};
				return 0;
			}
			
			i=0;
			cstr[0]++;
		//	printf("DBG %d %d\n", i, cstr[i]);
			while(cstr[i]>=ln) {
		//		printf("DBG2 %d %c\n", i, stro[cstr[i]]);
				cstr[i]=0;
				i++;
				cstr[i]++;
			}
		}
	}

	return 0;
}
