130H.md (909B)
1 Source: https://codeforces.com/problemset/problem/130/H 2 3 H. Balanced brackets 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 64 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters «+» and «1». For example, sequences «(())()», «()» and «(()(()))» are balanced, while «)(», «(()» and «(()))(» are not. 22 23 You are given a string which consists of opening and closing round brackets. Check whether it is a balanced bracket sequence. 24 25 Input 26 27 The only line of input contains a string between 1 and 100 characters long, inclusive. Each character in the string will be «(» or «)». 28 29 Output 30 31 Output «YES» if the bracket sequence is balanced, and «NO» otherwise (quotes for clarity only). 32 33 Examples 34 35 Input 36 37 ``` 38 (()(()))() 39 ``` 40 41 Output 42 43 ``` 44 YES 45 ``` 46 47 Input 48 49 ``` 50 ())() 51 ``` 52 53 Output 54 55 ``` 56 NO 57 ```