#!/usr/bin/ruby -w

def ok()
	puts "OK"
end

def error()
	puts "ERROR"
end

def testCount(count)
	return count < 2
end

def checkLine(line)
	line.gsub!(/-/,'+')
	if (/^\+|\+$|\[\+|\+\]/.match(line))
		return false
	end
	while (new_line = line.gsub(/\[([^\]]*)\]/) { "+#{$1}" }) != line
		line = new_line
	end
	base_count = 0
	index_count = 0
	var_count = 0
	line.split("+").each do |word|
		if word.length > 0
			if /^[0-9]+$/.match(word)
				next
			end
			if /^bx$|^bp$/i.match(word)
				base_count += 1
				unless testCount(base_count)
					return false
				end
				next
			end
			if /^si$|^di$/i.match(word)
				index_count += 1
				unless testCount(index_count)
					return false
				end
				next
			end
			if /^[a-z]$/.match(word)
				var_count += 1
				unless testCount(var_count)
					return false
				end
				next
			end
			return false
		end
	end
	return true
end

$stdin.each do |line|
	if line.length == 1 && line.chomp.length == 0
		break
	end
	if checkLine(line.chomp)
		ok()
	else
		error()
	end
end