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: import re
while True:
    s = input()
    if s=='.': break
    s = re.sub(u'[a-zA-Z .]+','',s)
    while '()' in s or '[]' in s:
        s = s.replace('()','').replace('[]','')
    print('yes' if len(s)==0 else 'no')

Python: import re
import sys
sys.setrecursionlimit(10**6)


def main():
  s=input()
  if s == ".":
    return
  s=re.sub(r'[a-zA-Z .]+',"",s)
  while "()" in s:
    s=s.replace("()","")
  while "[]" in s:
    s=s.replace("[]","")
  if s == "":
    print("yes")
  else:
    print("no")
  main()
  return

main()

Python: import re
while 1:
    s=input()
    if s==".":break
    s=s.replace(" ","").replace(".","")
    st=re.sub("[a-zA-Z]","",s)
    a1,a2,b1,b2=0,0,0,0
    while 1:
        if "()" in st or "[]" in st:st=st.replace("()","").replace("[]","")
        else:break
    print(["no","yes"][st==""])

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)

def dfs(string,bracket):
    i = 0
    while i < len(string):
        if bracket == '[' and string[i] == ']':
            return i
        elif bracket == '(' and string[i] == ')':
            return i
        elif string[i] == '(' or string[i] == '[':
            ret = dfs(string[i+1:],string[i])
            if ret  == False:
                return False
            i += ret
        i += 1
    return True if bracket == '' else False


while True:
    string = list(input())
    if len(string) == 1 and string[0] == '.':
        break
    ans = 'yes' if dfs(string,'') else 'no'
    print(ans)

Python: def parse(s, left, target_stack):
  if s[left] == "[":
    target_stack.append("]")
  if s[left] == "(":
    target_stack.append(")")
  
  if s[left] == "]":
    if target_stack and target_stack[-1] == "]":
      target_stack.pop()
    else:
      return False

  if s[left] == ")":
    if target_stack and target_stack[-1] == ")":
      target_stack.pop()
    else:
      return False

  left += 1
  if left == len(s):
    if target_stack:
      return False
    else:
      return True

  else:
    return parse(s, left, target_stack)

while True:
  s = input()
  if s == ".":
    break

  if parse(s, 0, []):
    print("yes")
  else:
    print("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: while True:
    s = input()
    if s[0] == '.': break
    r = []
    f = False
    for c in s:
        if c == '(' or c == '[':
            r.append(c)
        elif c == ')':
            if not r or r.pop() != '(':
                print("no")
                break
        elif c == ']':
            if not r or r.pop() != '[':
                print("no")
                break
    else:
        print("yes" if not r else "no")

Python: while 1:
    s=input()
    if s==".":
        break
    l1=0
    r1=0
    l2=0
    r2=0
    ans="yes"
    for i in range(len(s)):
        if s[i]=='(':
            l1+=1
        if s[i]==')':
            r1+=1
        if s[i]=='[':
            l2+=1
        if s[i]==']':
            r2+=1
        if l1<r1:
            ans="no"
        if l2<r2:
            ans="no"

    print(ans)

Python: while True :
    S = input()
    
    if(S == ".") :
        break
    
    else :
        B = list()
        b = -1
        for i in range(len(S)) :
            if(S[i] == "(" or S[i] == "[") :
                B.append(S[i])
                b += 1
                
            elif(S[i] == ")") :
                if(b > -1) :
                    if(B[b] == "(") :
                        del B[b]
                        b -= 1
                    else :
                        b = 0
                        break
                else :
                    b = 0
                    break
                
            elif(S[i] == "]") :
                if(b > -1) :
                    if(B[b] == "[") :
                        del B[b]
                        b -= 1
                    else :
                        b = 0
                        break
                else :
                    b = 0
                    break
                
            else :
                pass
            
        if(b == -1) :
            print("yes")
        else :
            print("no")

Python: def is_balanced(s):
    stack = []
    for c in s:
        if c == '(' or c == '[':
            stack.append(c)
        elif c == ')':
            if not stack:
                return "no"
            elif stack[-1] == '(':
                stack.pop()
            else:
                return "no"
        elif c == ']':
            if not stack:
                return "no"
            elif stack[-1] == '[':
                stack.pop()
            else:
                return "no"
    if stack:
        return "no"
    else:
        return "yes"

import sys

file_input = sys.stdin

lines = file_input.readlines()
lines = lines[:-1]
 
print('\n'.join(map(is_balanced, lines)))

Python: while True:
    s = input()
    if s[0] == '.': break
    r = []
    f = False
    for c in s:
        if c == '(' or c == '[':
            r.append(c)
        elif c == ')':
            if not r or r.pop() != '(':
                print("no")
                break
        elif c == ']':
            if not r or r.pop() != '[':
                print("no")
                break
    else:
        print("yes")

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 re
while 1:
    s=input()
    if s=='.':break
    s=re.sub(u'[A-Za-z .]','',s)
    while '()' in s or '[]' in s:
        s=s.replace('()','').replace('[]','')
    print(['yes','no'][bool(s)])

Python: while (True):
  st = input()
  if st == ".":
      quit()
  han = []
  ans = "yes"
  for i in st:
    if i == "(":
      han.append("maru")
    elif i == "[":
      han.append("kaku")
    elif i == ")":
      if han == []:
        ans = "no"
        break
      elif han[-1] == "maru":
        del han[-1]
      else:
        ans = "no"
        break
    elif i == "]":
      if han == []:
        ans = "no"
        break
      elif han[-1] == "kaku":
        del han[-1]
      else:
        ans = "no"
        break
  if ans == "no" or han != []:
    print("no")
  else:
    print(ans)