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: #!/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  == 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 True:
    s = input()
    if s == ".":
        break
    check = []
    ok = True
    for i in range(len(s)):
        if s[i] in ["(", "["]:
            check.append(s[i])
        elif s[i] == ")":
            if len(check) <= 0:
                ok = False
                break
            elif check.pop() != "(":
                ok = False
                break
        elif s[i] == "]":
            if len(check) <= 0:
                ok = False
                break
            elif check.pop() != "[":
                ok = False
                break
    if len(check) > 0:
        ok = False
    
    if ok:
        print("yes")
    else:
        print("no")

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

    stack = list()
    judge = True

    for c in s:
        if c == '(' or c == '[':
            stack.append(c)

        if c == ')':
            if stack and stack[-1] == '(':
                stack.pop()
            else:
                judge = False
                break

        if c == ']':
            if stack and stack[-1] == '[':
                stack.pop()
            else:
                judge = False
                break

    if judge and not stack:
        print("yes")
    else:
        print("no")

Python: while True:
    s = input()
    if s == '.': break
    pl = [c for c in s if c == '(' or c == ')' or c == '[' or c == ']']
    flag = False
    while True:
        if len(pl) == 0:
            flag = True
            break
        if len(pl) == 1: break
        flag2 = False
        for i in range(len(pl) - 1):
            if (pl[i] == '(' and pl[i + 1] == ')') or (pl[i] == '[' and pl[i + 1] == ']'):
                del pl[i + 1]
                del pl[i]
                break
            elif i == len(pl) - 2:
                flag2 = True
        if flag2: break
    print('yes' if flag else '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()
            elif line[i] == ']' or line[i] == ')':
                return 'no'
        elif line[i] == ']' or line[i] == ')':
            return 'no'

    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()
    tmp = []
    if s == '.' :
        break
    ans = True
    for i in range(len(s)) :
        if s[i] == '(' :
            tmp.append(s[i])
        elif s[i] == '[' :
            tmp.append(s[i])
        elif s[i] == ')' :
            if '(' not in tmp :
                ans = False
                break
            elif tmp[-1] == '(' :
                tmp.pop(-1)
            else :
                ans = False
                break
        elif s[i] == ']' :
            if '[' not in tmp :
                ans = False
                break
            elif tmp[-1] == '[' :
                tmp.pop(-1)
            else :
                ans = False
                break
    if len(tmp) != 0 or ans == False :
        print('no')
    else :
        print('yes')

Python: stack = []
flag = False

def rev(ch):
    if ch == ']':
        return '['
    else:
        return '('

while True:
    doc = input()[0:-1]
    if doc:
        n = len(doc)
        for i in range(n):
            ch = doc[i]
            if ch == '[' or ch == '(':
                stack.append(ch)
            if ch == ']' or ch == ')':
                if stack and stack[-1] == rev(ch):
                    stack.pop(-1)
                else:
                    flag = True
                    break
            print(stack)

        if stack or flag:
            print("no")
        else:
            print("yes")
    else:
        break

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 False
        elif c == ']':
            if stack[-1] == '[':
                stack.pop()
            else:
                return False
    else:
        return True

import sys

file_input = sys.stdin

for line in file_input:
    if line == '.\n':
        pass
    elif is_balanced(line):
        print("yes")
    else:
        print("no")

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:
            rr.append('yes')
        else:
            rr.append('no')

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


print(main())