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: while True:
    S = input()
    if S == ".":
        break
    
    brackets = []
    closed = True
    for c in S:
        if c in "([":
            brackets.append(c)
        elif c == ")":
            if not brackets or brackets[-1] != "(":
                closed = False
                break
            else:
                brackets.pop()
        elif c == "]":
            if not brackets or brackets[-1] != "[":
                closed = False
                break
            else:
                brackets.pop()
    
    if brackets:
        closed = False
        
    if closed:
        print("yes")
    else:
        print("no")

Python: def is_balanced(txt):
    round_brackets = []
    square_brackets = []

    for c in txt:
        try:
            if c == '(':
                round_brackets.append(len(square_brackets))
            elif c == ')':
                level = round_brackets.pop()
                if level != len(square_brackets):
                    return False
            elif c == '[':
                square_brackets.append(len(round_brackets))
            elif c == ']':
                level = square_brackets.pop()
                if level != len(round_brackets):
                    return False
        except IndexError:
            return False
    if len(round_brackets) == 0 and len(square_brackets)==0:
        return True
    else:
        return False


if __name__ == '__main__':
    # ??????????????\???
    # txt = 'So when I die (the [first] I will see in (heaven) is a score list).'
    while True:
        txt = input()
        if txt == '.':
            break

        # ??¬??§?????????????§£???
        ans = is_balanced(txt)

        # ???????????¨???
        if ans:
            print('yes')
        else:
            print('no')

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] == ']':
            return False
        elif string[i] == '(' or string[i] == '[':
            ret = dfs(string[i+1:],string[i])
            if ret is False:
                return False
            i += ret + 1
        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: while 1:
    a = list(input())
    if a == ['.']:break
    stack = []
    for i in a:
        if i =='(' :stack.append('(')
        elif i == '[':stack.append('[')
        elif i ==')':
            if len(stack) ==0:
                stack.append(0)
                break
            b = stack.pop()
            if b =='(':pass
            else:
                stack.append(b)
                break

        elif i ==']':
            if len(stack) == 0:
                stack.append(0)
                break
            b = stack.pop()
            if b =='[':pass
            else:
                stack.append(b)
                break
    if len(stack) == 0 and len(stack) == 0:print("yes")
    else:print("no")

Python: while True:
    S = input()
    if S==".":
        break
    a = [-1]
    b = [-1]
    ans = "yes"
    for i in range(len(S)):
        s = S[i]
        if s=="(":
            a.append(i)
        if s=="[":
            b.append(i)
        if s==")":
            if len(a)==1 or a[len(a)-1]<b[len(b)-1]:
                ans = "no"
                break
            else:
                del a[len(a)-1]
        if s=="]":
            if len(b)==1 or b[len(b)-1]<a[len(a)-1]:
                ans = "no"
                break
            else:
                del b[len(b)-1]
    if len(a)!=1 or len(b)!=1:
        ans = "no"
    print(ans)

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  is False:
                return False
            i += ret + 1
        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 main():
    while True:
        line = input()
        if line == ".": break
        line = line.split()

        k_list = []
        for item in line:
            for j in item:
                if j == "(" or j == ")" or j == "[" or j == "]":
                    k_list.append(j)

        while True:
            bef = k_list.copy()
            k_list = rem_mk(k_list)
            k_list = rem_kk(k_list)
            aft = k_list.copy()
            
            if bef == aft: break

        if k_list == []: print("yes")
        else: print("no")

    return

def rem_mk(a):
    for i in range(len(a) - 1):
        if a[i] == "(" and a[i + 1] == ")":
            del a[i + 1]
            del a[i]
            return a
    return a
def rem_kk(a):
    for i in range(len(a) - 1):
        if a[i] == "[" and a[i + 1] == "]":
            del a[i + 1]
            del a[i]
            return a
    return a
main()

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: #!/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])
            ret += 1
            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)