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 is_balanced(s):
    stack = [None]
    for c in s:
        if c == '(' or c == '[':
            stack.append(c)
        elif c == ')':
            if stack[-1] == '(':
                stack.pop()
            else:
                return "no"
        elif c == ']':
            if stack[-1] == '[':
                stack.pop()
            else:
                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: rev = {"(":"]", "[":")"}

while True:
    s = input()
    if s == '.':
        break
    stack = []
    flag = True
    for i in s:
        if i == '(' or i == '[':
            stack.append(i)
        if i == ')' or i == ']':
            if len(stack) == 0 or rev[stack[-1]] == i:
                flag = False
                break
            else:
                stack.pop()
    print("yes" if flag 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 or "[]" in s:
    s=s.replace("()","")
    s=s.replace("[]","")
  if s == "":
    print("yes")
  else:
    print("no")
  main()
  return

main()

Python: rev = {"(":")", "[":"]"}

while True:
    s = input()
    if s == '.':
        break
    stack = []
    flag = True
    for i in s:
        if i == '(' or i == '[':
            stack.append(i)
        if i == ')' or i == ']':
            if len(stack) == 0 or rev[stack[-1]] != i:
                flag = False
                break
            else:
                stack.pop()
    if len(stack) == 0 and flag:
        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 == ")" and q_list[now] != "(") or (i == "]" and 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: from collections import Counter
ans = []
while 1:
    s = list(str(input()))
    S = "".join(s)
    if S[0] == ".":
        break
    flag = 0
    stack = []
    for i in range(len(S)):
        if S[i] == "(":
            stack.append(S[i])
        if S[i] == "[":
            stack.append(S[i])
        if S[i] == ")":
            stack.append(S[i])
        if S[i] == "]":
            stack.append(S[i])
    c = Counter(stack)
    if c["{"] != c["}"]:
        print("no")
        flag = 2
    elif c["("] != c[")"]:
        print("no")
        flag = 2
    elif c["["] != c["]"]:
        print("no")
        flag = 2

    m = len(stack)
    if flag == 0:
        while len(stack) > 0:
            if flag == 1:
                break
            if stack[0] == ")" or stack[0] == "]":
                print("no")
                flag = 1
                break
            for i in range(1, m):
                if stack[i] == ")":
                    if stack[i - 1] == "(":
                        stack.pop(i)
                        stack.pop(i - 1)
                        m = len(stack)
                        break
                    else:
                        print("no")
                        flag = 1
                        break
                if stack[i] == "]":
                    if stack[i - 1] == "[":
                        stack.pop(i)
                        stack.pop(i - 1)
                        m = len(stack)
                        break
                    else:
                        print("no")
                        flag = 1
                        break
            if flag == 1:
                break
        if flag == 0:
            print("yes")

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


def main():
  s=input()
  if s == ".":
    return
  s=re.sub(u'[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: from collections import deque
while True:
    S = input()
    if S == ".":
        break
    que = deque()
    flag = True
    for s in S:
        if s == "(":
            que.append(1)
        elif s == "[":
            que.append(-1)
        elif s == ")" or s == "]":
            if len(que) <= 0:
                flag = False
                break
            temp1 = -1 if s == ")"else 1
            temp2 = que.pop()
            if temp1 + temp2 != 0:
                flag = False
                break
    if len(que) != 0:
        flag = False

    if flag:
        print("yes")
    else:
        print("no")

Python: while 1:
    s=input()
    if s=='.':
        break
    stk=[]
    try:
        for c in s:
            if c in '([':
                stk.append(c)
            elif c == ')' and stk[-1]=='(':
                del stk[-1]
            elif c == ']' and stk[-1]=='[':
                del stk[-1]
            elif c in '()[]':
                print('no')
                break
        else:
            if len(stk)==0:
                print('yes')
            else:
                print('no')
    except:
        print('no')

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

    st = []
    is_valid = True
    for c in s:
        if c == "(": st.append(c)
        if c == "[": st.append(c)
        if c == ")":
            if (not st) or st[-1] != "(":
                is_valid = False
                break
            else:
                st.pop()
        if c == "]":
            if (not st) or st[-1] != "[":
                is_valid = False
                break
            else:
                st.pop()
    if st:
        is_valid = False

    print( "yes" if is_valid else "no" )

Python: from collections import deque

def solve(s):
    dq = deque()
    for i in range(len(s)):
        if   s[i]=='(':dq.append(s[i])
        elif s[i]=='[':dq.append(s[i])
        elif s[i]==')':
            if len(dq)==0:return ('no')
            a = dq.pop()
            if a!='(':return ('no')
        elif s[i]==']':
            if len(dq)==0:return ('no')
            a = dq.pop()
            if a!='[':return ('no')
    if len(dq)==0:return ('yes')
    return ('no')

def main():
    while True:
        s = input()
        if s == '.':break
        print (solve(s))


if __name__ == '__main__':
    main()