#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
int first_digit[10] ={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int last_digit[10] ={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
char *numberstring = argv[1];
int j;
int nextdigit;
for (j=0;j<strlen(numberstring);j++) {
nextdigit = (int)(numberstring[j])-48; /* 48 = ascii 0*/
if (first_digit[nextdigit] > -1) {
last_digit[nextdigit] = j;
} else {
first_digit[nextdigit] = j;
}
}
int i;
int maxdist =0;
for(i=1;i<=9;i++)
maxdist =(maxdist<last_digit[i]-first_digit[i])?last_digit[i]-first_digit[i]:maxdist;
/* we are off by one in this calculation, let's cheat and decrement our output */
printf("%d\n", maxdist-1);
}