#include #include #include int main(int argc, char *argv[]) { #define CASE_BIT ('A' ^ 'a') #define MAX_LENGTH 65536 static char stack[MAX_LENGTH]; FILE *input; int remove, c, shortest = INT_MAX, top; for (remove = 'a'; remove <= 'z'; ++remove) { if (input = fopen("input.txt", "r")) { top = -1; while (isalpha(c = fgetc(input))) { if ((c | CASE_BIT) != remove) { if (top >= 0 && (c ^ CASE_BIT) == stack[top]) { --top; } else { if (++top < MAX_LENGTH) stack[top] = c; else return 1; } } } fclose(input); } else return 2; if (shortest > top) shortest = top; } printf("%d\n", shortest + 1); return 0; }