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: def check():
    while True:
        l=len(p)
        if l==0 or l==1: return l-1
        for i in range(l-1):
            if p[i]+p[i+1]=='()' or p[i]+p[i+1]=='[]':
                del p[i+1],p[i]
                break
        if l==len(p):return False
while True:
    s=input()
    if s=='.':break
    p = [c for c in s if c=='(' or c ==')' or c=='['or c==']']
    print('yes' if check() else 'no')

Python: #!/usr/bin/env python3

if __name__ == '__main__':

    while True:
        s = input()
        if s == '.':
            break
        s2 = ''
        for i in s:
            if i == '(' or i == ')' or i == '[' or i == ']':
                s2 += i
        cnt = 0
        while cnt <= 50:
            s2 = s2.replace('()', '')
            s2 = s2.replace('[]', '')
            cnt += 1
        if len(s2) != 0:
            print('no')
        else:
            print('yes')

Python: while True:
    s = input()
    if s == ".":
        break
    L = []
    f = 0
    for c in s:
        if c in "([":
            L.append(c)
        elif c == ")":
            if len(L) > 0 and L[-1] == "(":
                L.pop()
            else:
                f += 1
                break
        elif c == "]":
            if len(L) > 0 and L[-1] == "[":
                L.pop()
            else:
                f += 1
                break
    
    if len(L) == 0 and f == 0:
        print("yes")
    else:
        print("no")

Python: def check():
    while True:
        l=len(p)
        if l==0 or l==1: return l-1
        for i in range(l-1):
            if p[i]+p[i+1]=='()' or p[i]+p[i+1]=='[]':
                del p[i+1],p[i]
                break
        if l==len(p):return False
while True:
    s=input()
    if s=='.':break
    p = [c for c in s if c=='(' or c ==')' or c=='['or c==']']
    print('yes' if check() else 'no')

Python: import sys

def solve():
    while 1:
        s = sys.stdin.readline().rstrip()

        if s == '.':
            return

        stack = []

        for ch in s:
            if ch == '(' or ch == '[':
                stack.append(ch)
            elif ch == ')':
                if stack and stack[-1] == '(':
                    stack.pop()
                else:
                    print('no')
                    break
            elif ch == ']':
                if stack and stack[-1] == '[':
                    stack.pop()
                else:
                    print('no')
                    break
        else:
            print('yes')


if __name__ == '__main__':
    solve()

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 == ")":
            if now == -1:
                ans = "no"
            elif q_list[now] == "(":
                now -= 1
            else:
                ans = "no"
        elif i == "]":
            if now == -1:
                ans = "no"
            elif q_list[now] == "[":
                now -= 1
            else:
                ans = "no"
        if ans == "no":
            break
    ans_list.append(ans)

for i in ans_list:
    print(i)

Python: def is_balanced(txt):
    """ ????????????????????????????????¨??????????????¶
    1. ????????????????????¬??§(???(???)?????????????????????????????¬??§(???)???)??????????????????????????????
    2. ????????????????§???¬??§(???[???)?????????????????????????§???¬??§(???]???)??????????????????????????????
    3. ?????????????????¬??§??????????????????????????¬??§????????????
    4. ??¬??§???????????????????????§???????????????????????????????????¬??§????????°?????¬??§??¨?????????????????¨????????????
    ??? ????????????????????????????????¬??§???????????§?????£??????pop()??¨??????????????????????????????????????????????????????????????????????????¨

    5. ?????????????????????????????¬??§??¨?????¬??§????????????????????????????????????????????????????????§ ??¬??§??????????????????????????????
    ??? '( [  ) ]' ??????????????????????????????????????????NG
    """
    round_brackets = []  # ?????¬??§????¨??????¨????????????
    square_brackets = []  # ??§??¬??§??¨

    for c in txt:
        if c == '(':
            round_brackets.append(len(square_brackets))  # '('?????????????????????[]?????¶???????¨???¶????????????
        elif c == ')':
            try:  # ')'?????????????????¨pop()??¨????????§??????????????????????????§
                level = round_brackets.pop()
                if level != len(square_brackets):  # ')'??§???????????????[]?????¶??????'('???????????¨????????¬????????§???????????°?????¶5????????????????????????
                    return False
            except IndexError:
                return False
        elif c == '[':
                square_brackets.append(len(round_brackets))
        elif c == ']':
            try:
                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 python3
#aoj b
import re
from collections import deque

while 1:
    x = list(input())
    if x[0] == ".":
        break

    stack = deque()
    f = 1
    for i in range(len(x)):
        for j in range(len(x[i])):
            if x[i][j] == '(':
                stack.append('(')
            elif x[i][j] == '[':
                stack.append('[')
            elif x[i][j] == ')':
                if len(stack) == 0:
                    f = 0
                elif stack.pop() != '(':
                    f = 0
            elif x[i][j] == ']':
                if len(stack) == 0:
                    f = 0
                elif stack.pop() != '[':
                    f = 0
    if len(stack) != 0:
        f = 0
    if f:
        print('yes')
    else:
        print('no')