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 1:
    k=[]
    l=input()
    if l==".":break
    f=False
    for i in l:
        if f:break
        if i=="[" or i=="(":
            k.append(i)
        elif i=="]":
            try:
                if k.pop()!="[":
                    f=True
            except:
                f=True
        elif i==")":
            try:
                if k.pop()!="(":
                    f=True
            except:
                f=True
    if not k and not f:print("yes")
    elif k:print("no")

Python: while True:
    flg = True
    S = input()
    if S == '.':
        exit()
    brackets = []
    for c in S:
        if c == '[':
            brackets.append('[')
        elif c == ']':
            if len(brackets) == 0:
                flg = False
                break
            if brackets.pop() != '[':
                flg = False
                break
        elif c == '(':
            brackets.append('(')
        elif c == ')':
            if len(brackets) == 0:
                flg = False
                break
            if brackets.pop() != '(':
                flg = False
                break
        else:
            pass
    if len(brackets) > 0:
        flg = False
    if flg:
        print('yes')
    else:
        print('no')

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")
        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: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    dd = [(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1)]

    while True:
        s = S()
        if s == '.':
            break
        mc = 0
        kc = 0
        f = True
        st = []
        for c in s:
            if c == '(':
                mc += 1
                st.append(1)
            elif c == ')':
                if mc < 1 or st[-1] == 0:
                    f = False
                    break
                mc -= 1
                st = st[:-1]
            elif c == '[':
                kc += 1
                st.append(0)
            elif c == ']':
                if kc < 1 or st[-1] == 1:
                    f = False
                    break
                kc -= 1
                st = st[:-1]
        if f and mc == 0 and kc == 0:
            rr.append('yes')
        else:
            rr.append('no')

    return '\n'.join(map(str, rr))


print(main())

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:
            if not stack:
                print('yes')
            else:
                print('no')
                
if __name__ == '__main__':
    solve()

Python: def ok(s):
    stack = []
    for c in s:
        if c in '([':
            stack.append(c)
        elif c in ')]':
            if len(stack) == 0: return False
            e = stack.pop()
            if (e+c) not in ('()','[]'):
                return False
    return False if stack else True

while True:
    S = input()
    if S == '.': break
    print('yes' if ok(S) else '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

    ans = True
    stack = []
    for i in s:
        if i == '[' or i == '(':
            tmp = 1
            if i == '[':
                tmp = -1
            if not len(stack) or stack[-1] * tmp < 0:
                stack.append(tmp)
            else:
                stack[-1] += tmp

        if i == ']' or i == ')':
            tmp = 1
            if i == ']':
                tmp = -1
            if not len(stack) or stack[-1] * tmp < 0:
                ans = False
                break
            else:
                stack[-1] -= tmp
                if not stack[-1]:
                    stack = stack[0:-1]

    if len(stack):
        ans = False

    print('yes' if ans else 'no')