#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <ctime>
#include <cassert>
#include <utility>

using namespace std;

string S;
int N;

int main() {
//	freopen("date.in", "r", stdin);
//	freopen("date.out","w", stdout);
	
	while(getline(cin, S)) {
        N = S.size();
        bool ok = true;
        for(int i = 0; i < N; i++)
            if(!isalnum(S[i]) && S[i] != '+' && S[i] != '-' && S[i] != '[' && S[i] != ']') {
                ok = false;
            }
        if(!ok) {
            cout << "ERROR\n";
            continue;
        }
        // toate sunt caractere valide
        
        vector<string> vars;
        int k = 0;
        while(k < N) {
            while(k < N && !isalpha(S[k]))
                k++;
            if(k == N)
                break;
            string crt = "";
            while(k < N && isalpha(S[k]))
                crt += S[k++];
            vars.push_back(crt);
        }
        ok = true;
        int base = 0;
        int idx = 0;
        int var = 0;
        for(vector<string> :: iterator it = vars.begin(); it != vars.end(); it++) {
            string s = *it;
            if(s.size() == 1) {
                if(isupper(s[0]))
                    ok = false;
                else
                    var++;
            }
            else if(s.size() == 2) {
                s[0] = tolower(s[0]);
                s[1] = tolower(s[1]);
                if(s == "bx" || s == "bp") base++;
                else if(s == "si" || s == "di") idx++;
                else ok = false;
            }
            else ok = false;
        }
        if(base > 1 || idx > 1 || var > 1)
            ok = false;
        if(!ok) {
            cout << "ERROR\n";
            continue;
        }
        // toate variabilele sunt valide
        
        int p = 0;
        ok = true;
        for(int i = 0; i < N; i++)
            if(S[i] == '[')
                p++;
            else if(S[i] == ']') {
                if(p == 0)
                    ok = false;
                p--;
            }
        if(!ok) {
            cout << "ERROR\n";
            continue;
        }
        
        cout << "OK\n";
	}
	
	return 0;
}