#include <cstdio>
#include <stack>

using namespace std;

 char s[1001];
 stack <char> st;

 bool litera (char ch) {
     return ch >= 'a' && ch <= 'z';
 }

 bool B (char ch) {
     return ch == 'B';
 }

 bool D (char ch) {
     return ch == 'D';
 }

  bool X (char ch) {
     return ch == 'X';
 }

  bool I (char ch) {
     return ch == 'I';
 }

  bool P (char ch) {
     return ch == 'P';
 }

  bool S (char ch) {
     return ch == 'S';
 }

 bool cifra (char ch) {
     return ch >= '0' && ch <= '9';
 }

 bool semn (char ch) {
     return (ch == '+' || ch == '-' || ch == '[' || ch == ']');
 }

int main () {
    long i, v, r, error, ind;

   /* freopen ("a.in", "r", stdin);
    freopen ("a.out", "w", stdout);*/

    while (gets (s)) {
        v = r = ind = 0;
        error = 0;
        for (i = 0; s [i] && !error; i ++) {
            if (!litera (s [i]) && !B (s [i]) && !P (s [i]) && !D (s [i]) && !X (s [i]) && !S (s [i]) && !I (s [i]) && !cifra(s [i]) && !semn(s [i]))
                error = 1;
            if (s [i] == 'B' || s [i] == 'b')
              {
                if (s [i + 1] == 'X' || s [i + 1] == 'x')
                    if (r == 1)
                        error = 1;
                    else {
                        r = 1;
                        i ++;
                    }
                else
                    if (s [i + 1] == 'P' || s [i + 1] == 'p')
                        if (r == 1)
                            error = 1;
                        else {
                            r = 1;
                            i ++;
                        }
                    else
                        error = 1;}
            else
            if (s [i] == 'S' || s [i] == 's') {
                if (s [i + 1] == 'I' || s [i + 1] == 'i')
                    if (ind == 1)
                        error = 1;
                    else {ind = 1;
                     i ++;}
                else
                    error = 1;
            }
            else
            if (s [i] == 'D' || s [i] == 'd') {
                if (s [i + 1] == 'I' || s [i] == 'i')
                    if (ind == 1)
                        error = 1;
                    else {ind = 1;i ++;}
                else
                    error = 1;
            }
            else
            if (s [i] >= 'a' && s [i] <= 'z') {
                if (v == 1)
                    error = 1;
                else v = 1;
            }
            else
            if (s [i] == '+' && (s [i + 1] == ']' || s [i + 1] == NULL))
                error = 1;
            else
            if (s [i] == '-' && (s [i + 1] == ']' || s [i + 1] == NULL))
                error = 1;
            else
            if (s [i] == '+' && ((i && s [i - 1] == '[') || i == 0))
                error = 1;
            else
            if (s [i] == '-' && ((i && s [i - 1] == '[') || i == 0))
                error = 1;

        }
        if (error == 1)
            printf ("ERROR\n");
        else {
            //verif paranteze
            st.push (s [0]);
            for (i = 1;s[i] && !error ; i ++)
                if (s [i] == ']') {
                    while (!st.empty () && st.top () != '[')
                        st.pop ();
                    if (st.empty () == 1)
                        error = 1;
                    if (!st.empty())
                        st.pop ();
                }
                else st.push (s [i]);
           while (!st.empty () && !error) {
                if (st.top () == '[')
                    error = 1;
                    st.pop ();
           }
         if (error == 1)
            printf ("ERROR\n");
        else
            printf ("OK\n");
        }
    }
    return 0;
}