fork download
  1. import sys
  2. input = sys.stdin.readline
  3.  
  4. n = int(input())
  5.  
  6. for _ in range(n):
  7. stc = []
  8. str = list(input())
  9. f = 0 # No 여부
  10. for s in str:
  11. if s == '(':
  12. stc.append(s)
  13. else:
  14. if len(stc) > 0 :
  15. stc.pop()
  16. else:
  17. print('NO')
  18. f = 1
  19. break
  20. if f == 0 and len(stc) == 0:
  21. print('YES')
  22. elif f == 0 and len(stc) > 0:
  23. print('NO')
Success #stdin #stdout 0.04s 9628KB
stdin
1
()()()()(()()())()
stdout
NO