#include #include #include char S[1024]; int main() { //freopen("test.in", "r", stdin); while (true) { bool hasB = false; bool hasI = false; bool hasV = false; int nrp = 0; int i; fgets(S+1, 1024, stdin); S[0] = '['; if (S[strlen(S)-1] == '\n') S[strlen(S)-1] = ']'; else S[strlen(S)] = ']'; for (i=0; S[i]!='\0' && S[i] !='\n'; ++i) { //printf("%c", S[i]); if (tolower(S[i]) == 'b' && (tolower(S[i+1])=='x' || tolower(S[i+1])=='p')) { ++i; if (hasB) break; hasB = true; } else if (tolower(S[i+1]) == 'i' && (tolower(S[i])=='s' || tolower(S[i])=='d')) { ++i; if (hasI) break; hasI = true; } else if ('a' <= S[i] && S[i] <= 'z') { if (isdigit(S[i+1]) || isalpha(S[i+1])) break; if (hasV) break; hasV = true; } else if (S[i] == '+' || S[i] == '-') { if (i == 0 || S[i-1] == '[' || S[i+1] == '\0' || S[i+1] == ']') break; } else if (S[i] == '[') ++nrp; else if (S[i] == ']') { --nrp; if (nrp < 0) break; } else if (S[i] < '0' || S[i] > '9') { if (isdigit(S[i+1]) || isalpha(S[i+1])) break; } } if ((S[i] == '\0' || S[i] == '\n') && nrp == 0) printf("OK\n"); else printf("ERROR\n"); if (feof(stdin)) return 0; } return 0; }