#include #include #include #include #include #include #include #include using namespace std; string S; void solve(); int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif getline(cin, S); while (cin.eof() != true) { solve(); getline(cin, S); } #ifndef ONLINE_JUDGE while (1); #endif } void solve() { int i, lg; int v = 0, rb = 0, ri = 0, pd = 0; lg = S.length(); for (i = 0; i < lg; ++i) { if ((S[i] == '+' || S[i] == '-') && (v | rb | ri) == 0) { cout << "ERROR\n"; return; } else if (i < lg && (S[i] == '+' || S[i] == '-') && S[i + 1] == ']') { cout << "ERROR\n"; return; } else if (i > 0 && (S[i] == '+' || S[i] == '-') && S[i - 1] == '['){ cout << "ERROR\n"; return; } else if (S[i] == '[') { ++pd; } else if (i < lg - 1 && tolower(S[i]) == 'b' && (tolower(S[i + 1]) == 'p' || tolower(S[i + 1]) == 'x')) { if (rb == 1) { cout << "ERROR\n"; return; } ++i; ++rb; } else if (i < lg - 1 && tolower(S[i + 1]) == 'i' && (tolower(S[i]) == 's' || tolower(S[i]) == 'd')) { if (ri == 1) { cout << "ERROR\n"; return; } ++i; ++ri; } else if (isdigit(S[i])) { while (i < lg && isdigit(S[i])) { ++i; } if (i < lg && S[i] != '+' && S[i] != '-' && S[i] != '[' && S[i] != ']') { cout << "ERROR\n"; return; } if (i < lg && S[i] == '[') ++pd; if (i < lg && S[i] == ']') --pd; } else if (S[i] == ']') { --pd; if (pd < 0) { cout << "ERROR\n"; return; } } else if (isalpha(S[i])) { if (i < lg - 1 && isalpha(S[i + 1])) { cout << "ERROR\n"; return; } if (tolower(S[i]) != S[i]) { cout << "ERROR\n"; return; } ++v; if (v == 2) { cout << "ERROR\n"; return; } } else if (S[i] != '+' &&S[i] != '-') { cout << "ERROR\n"; return; } } if (pd != 0) { cout << "ERROR\n"; return; } if (S[lg - 1] != ']' && !isdigit(S[lg - 1]) && !isalpha(S[lg - 1])) { cout << "ERROR\n"; return; } cout << "OK\n"; }