fork download
  1. # your code goes here
  2. a = []
  3. b = []
  4. c = int(input())
  5. d = 0
  6. e = 0
  7. response1 = ""
  8. for i in range(c):
  9. text = input()
  10. try:
  11. for j in range(len(text)):
  12. if text[j] =="(" and d >= e :
  13. d += 1
  14. elif text[j] ==")" and d < e:
  15. response = "NO"
  16. else:
  17. e += 1
  18. if d == e:
  19. response = "YES"
  20. else:
  21. response = "NO"
  22. d = 0
  23. e = 0
  24. response1 += response + "\n"
  25. except:
  26. response1 += "NO" + "\n"
  27. print(response1.strip())
Success #stdin #stdout 0.04s 9656KB
stdin
1
(())()(
stdout
YES