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: 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 == ".":
        break
    k = []
    for c in s:
        if c == "(":
            k.append(c)
        elif c == "[":
            k.append(c)
        elif c == ")":
            if k != [] and k[-1] == "(":
                k.pop()
            else:
                print("no")
                break
        elif c == "]":
            if k != [] and k[-1] == "[":
                k.pop()
            else:
                print("no")
                break
    else:
        if k == []:
            print("yes")

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
    if now == 0:
        ans = "no"
    ans_list.append(ans)

for i in ans_list:
    print(i)

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
    if now >= 0:
        ans = "no"
    ans_list.append(ans)

for i in ans_list:
    print(i)

Python: "世界の天秤"
pattern = ('()', '[]')

while True:
    S = input()
    if S == '.':
        break
    sentence_list = list(S)
    target = ('(', ')', '[', ']')
    for i in range(len(sentence_list)):
        if sentence_list[i] not in target:
            sentence_list[i] = ''

    sentence = ''.join(sentence_list).strip()

    while True:
        sentence_len = len(sentence)
        sentence = sentence.replace('[]', '')
        sentence = sentence.replace('()', '')
        if sentence_len == len(sentence):
            break

    if len(sentence) == 0:
        print('yes')
    else:
        print('no')

Python: 
# solve function
def solve(line):
    stack = []

    for i in range(len(line)):
        if line[i] == '(' or line[i] == '[':
            stack.append(line[i])
        elif len(stack) > 0:
            if line[i] == ')' and stack[-1] == '(':
                stack.pop()
            elif line[i] == ']' and stack[-1] == '[':
                stack.pop()

    if len(stack) == 0:
        return 'yes'
    else:
        return 'no'



# main function
if __name__ == '__main__':
    while True:
        line = input()

        if line == ".":
            break

        result = solve(line)
        print(result)

Python: while True:
    s = input()
    if s == ".":
        break
    s = "".join([c for c in s if c in "()[]"])
    while "()" in s or "[]" in s:
        s = s.replace("()", "")
        s = s.replace("[]", "")
    print("no" if s else "yes")

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: 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)
    print(blackets)
    if isBalancedNum(blackets):
        if isBalanced(blackets):
            print("yes")
        else:
            print("no")
    else:
        print("no")

Python: def main(s):
    s = "".join(list(s.split()))
    bra1 = 0
    bra2 = 0
    for i in range(len(s)):
        if s[i] != "(" and s[i] != ")" and s[i] != "[" and s[i] != "]":
            continue
        if s[i] == "(":
            if bra1 == 0:
                bra10 = i
            bra1 += 1
        if s[i] == ")":
            bra1 -= 1
            if bra1 == 0:
                if not main(s[bra10 + 1:i]):
                    return False
        if s[i] == "[":
            if bra2 == 0:
                bra20 = i
            bra2 += 1
        if s[i] == "]":
            bra2 -= 1
            if bra2 == 0:
                if not main(s[bra20 + 1:i]):
                    return False
        if bra1 < 0 or bra2 < 0:
            return False
    if bra1 > 0 or bra2 > 0:
        return False
    return True

while 1:
    s = input()
    if s == ".":
        break
    print("yes" if main(s) else "no")

Python: S = {']':'[',')':'('}
while 1:
    l = input()
    if l == '.':break

    lst = []
    flg = True
    for w in list(l):
        if w == '[' or w == '(':
            lst.append(w)
        if w== ']' or w == ')':
            if len(lst) > 0 and S[w] == lst[-1]:
                lst.pop(-1)
            else:
                flg = False
                break
    print('yes' if flg and len(lst) == 0 else 'no')