#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<fstream>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

typedef long long int LL;
typedef pair<int,int> PII;

const int INF = (1<<31)-1;
const LL LINF = (1LL<<63)-1;
const long double PI = 3.14159265;

const int NMAX = 100000+5;
const int MMAX = 100000+5;
const int KMAX = 100000+5;
const int PMAX = 100000+5;
const int LMAX = 100000+5;

void files();

int N;
char S[NMAX];

int main()
{
    int i,index,base,sign,brackets,variable,ok;
    char c;

    //files();

    for(; fgets(S+1,NMAX,stdin);)
    {
        N=strlen(S+1);
        S[N]=0;
        N--;
        ok=1;
        index=0;
        base=0;
        variable=0;
        brackets=0;
        sign=0;
        for(i=1; i<=N; i++)
        {
            c=S[i];
            if((c=='B' || c=='b') && (S[i+1]=='X' || S[i+1]=='x' || S[i+1]=='P' || S[i+1]=='p'))
            {
                if(base) ok=0;
                base=1;
                sign=0;
                i++;
                continue;
            }
            if((c=='S' || c=='s' || c=='D' || c=='d') && (S[i+1]=='I' || S[i+1]=='i'))
            {
                if(index) ok=0;
                index=1;
                sign=0;
                i++;
                continue;
            }
            if('a'<=c && c<='z' && !('a'<=S[i+1] && S[i+1]<='z'))
            {
                if(variable) ok=0;
                variable=1;
                sign=0;
                continue;
            }
            if(c=='[')
            {
                brackets++;
                if(S[i+1]=='+' || S[i+1]=='-') ok=0;
                sign=0;
                continue;
            }
            if(c==']')
            {
                if(sign) ok=0;
                brackets--;
                if(brackets<0) ok=0;
                sign=0;
                continue;
            }
            if(c=='+' || c=='-')
            {
                sign=1;
                continue;
            }
            if('0'<=c && c<='9')
            {
                sign=0;
                continue;
            }
            ok=0;
        }
        if(brackets || sign) ok=0;
        if(ok) printf("OK\n");
        else printf("ERROR\n");
    }

    return 0;
}

void files()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}