Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)

	for {
		var s string
		s = nextString()
		if s == "." {
			break
		}
		var st []byte
		is_valid := true

		for _, value := range s {
			if value == '(' {
				st = append(st, byte(value))
			}
			if value == '[' {
				st = append(st, byte(value))
			}
			if value == ')' {
				if len(st) == 0 || st[len(st)-1] != '(' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
			if value == ']' {
				if len(st) == 0 || st[len(st)-1] != '[' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
		}
		if len(st) != 0 {
			is_valid = false
		}
		if is_valid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

Python: from collections import deque

def check(line):
    Q = deque([])
    for s in line:
        if s in ['(', '[']:
            Q.append(s)
        elif s in [')', ']']:
            if len(Q) == 0:
                return 0
            p = Q.pop()
            if s == ')' and p != '(':
                return 0
            elif s == ']' and p != '[':
                return 0
            else:
                continue
    else:
        if len(Q) != 0:
            return 0
        else:
            return 1



ans = []
while 1:
    line = input()
    if line == '.': break
    ans += ['yes' if check(line) else 'no']

print('\n'.join(ans))

Python: 
while True:
	s = input()
	if s == '.':
		break
	flag = False
	stack = []
	for c in s:
		if c in '[(':
			stack.append(c)
		elif c in '])':
			if c == ']' and len(stack)>0 and stack[-1] == '[':
				stack.pop()
			elif c == ')' and len(stack)>0 and stack[-1] == '(':
				stack.pop()
			else:
				flag = True
				break
	if stack or flag:
		print('no')
	else:
		print('yes')

Python: import re
def isSet(r,l):
    while True:
        if not(l): return
        if l[0]==r:
            del l[0]
            return l
        else:
            x = ')' if l[0]=='(' else ']'
            del l[0]
            l = isSet(x,l)

while True:
    s = input()
    if s=='.': break
    l = list(re.sub(r'[a-zA-Z. ]+','',s))
    while True:
        if not(l): break
        r = ')' if l[0]=='(' else ']'
        del l[0]
        l = isSet(r,l)
    print('yes' if l==[] else 'no')

Python: import re
def isSet(r,l):
    while True:
        if not(l): return
        if l[0]==r:
            del l[0]
            return l
        else:
            x = ')' if l[0]=='(' else ']'
            del l[0]
            l = isSet(x,l)

while True:
    s = input()
    if s=='.': break
    l = list(re.sub(r'[a-zA-Z. ]+','',s))
    while True:
        if not(l): break
        r = ')' if l[0]=='(' else ']'
        del l[0]
        l = isSet(r,l)
    print('yes' if l==[] else 'no')

Python: import re
def isSet(r,l):
    while True:
        if not(l): return
        if l[0]==r:
            del l[0]
            return l
        elif l[0]=='(' or l[0]=='[':
            x = ')' if l[0]=='(' else ']'
            del l[0]
            l = isSet(x,l)
        else: return None
t = []
while True:
    s = input()
    if s=='.': break
    l = list(re.sub(r'[a-zA-Z. ]+','',s))
    while True:
        if not(l): break
        if l[0]==')' or l[0]==']':
            l = None
            break
        r = ')' if l[0]=='(' else ']'
        del l[0]
        l = isSet(r,l)
    print('yes' if l==[] else 'no')

Python: ans_list = []
while True:
    s = input()
    if s == ".":
        break
    q_list = ["" for i in range(len(s))]
    now = -1
    ans = "yes"
    for i in list(s):
        if i == "(" or i == "[":
            now += 1
            q_list[now] = i
        elif i == ")" or i == "]":
            if (i == ")" and q_list[now] == "(") or (i == "]" and q_list[now] == "["):
                now -= 1
            elif now < 0 or i != q_list[now]:
                #print(i, now, q_list)
                ans = "no"
                break
        if ans == "no":
            break
    ans_list.append(ans)

for i in ans_list:
    print(i)

Python: def makeBlackets(strings):
    blackets=[]
    for i in range(len(strings)):
        char=strings[i]
        if char=='[' or char=='(' or char==']' or char==')':
            blackets.append(char)
    return blackets
def isBalancedNum(blackets):
    lB=0
    rB=0
    for i in range(len(blackets)):
        if blackets[i]==')' or blackets[i]==']':
            lB+=1
        else:
            rB+=1
    
    return lB==rB
def isBalanced(blackets):
    while len(blackets)!=0:
        if "()" in blackets:
            blackets=blackets.replace("()","")
        elif "[]" in blackets:    
            blackets=blackets.replace("[]","")
        else:
            break
    return len(blackets)==0
while True:
    strings=input()
    if strings==".":
        break
    blacket=makeBlackets(strings)
    blackets=''.join(blacket)
    if isBalancedNum(blackets):
        if isBalanced(blackets):
            print("yes")
        else:
            print("no")
    else:
        print("no")

Python: import re
def isSet(r,l):
    while True:
        if not(l): return
        if l[0]==r:
            del l[0]
            return l
        elif l[0]=='(' or l[0]=='[':
            x = ')' if l[0]=='(' else ']'
            del l[0]
            l = isSet(x,l)
        else: return None

while True:
    s = input()
    if s=='.': break
    l = list(re.sub(r'[a-zA-Z. ]+','',s))
    while True:
        if not(l): break
        r = ')' if l[0]=='(' else ']'
        del l[0]
        l = isSet(r,l)
    print('yes' if l==[] else 'no')

Python: while 1:
    k=[]
    l=input()
    if l==".":break
    f=False
    for i in l:
        if f:break
        if i=="[" or i=="(":
            k.append(i)
        elif i=="]":
            try:
                if k.pop()!="[":
                    f=True
            except:
                f=True
        elif i==")":
            try:
                if k.pop()!="(":
                    f=True
            except:
                f=True
    if not k and not f:print("yes")
    elif k or f:print("no")

Python: while 1:
  l=input()
  if l==".":break
  sa=[]
  sb=[]
  f=True
  for i in l:
    if i=="(":
      sa.append(1)
    elif i==")":
      try:
        _=sa.pop()
      except:
        print("no")
        f=False
        break
    elif i=="[":
      sb.append(1)
    elif i=="]":
      try:
        _=sb.pop()
      except:
        print("no")
        f=False
        break
  if not sa and not sb and f:
    print("yes")

Python: import sys

sys.setrecursionlimit(1000000)


class St():
    def __init__(self, s):
        self.s = s
        self.i = 0

def expression(st, num):
    while (not st.s[st.i]=="."):
        if (st.s[st.i] == "("):
            if (not factor1(st)):
                return False

        elif (st.s[st.i] == "["):
            if (not factor2(st)):
                return False

        elif (not st.s[st.i] in [")", "]"]):
            st.i += 1

        else:
            if ((num==1) and (st.s[st.i]==")")) or ((num==2) and (st.s[st.i]=="]")):
                break
            else:
                return False
        if (st.i >= len(st.s)):
            return False
    return True
    
    
def factor1(st):
    st.i += 1
    if (st.s[st.i]=="."):
        return False
    if (expression(st, 1)):
        st.i += 1
        return True
    return False

def factor2(st):
    st.i += 1
    if (st.s[st.i]=="."):
        return False
    if (expression(st, 2)):
        st.i += 1
        return True
    return False


def solve(s):
    st = St(s)
    return expression(st, 0)

def main():
    ans = []
    while True:
        s = input()
        if (s=="."):
            break
        ans.append(solve(s))
    for i in ans:
        print("yes" if i else "no")


main()