LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Data types and IOC++ syntaxModuloVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of Eratosthenes
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

Balanced Brackets

EasyProblem #10
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Which opening bracket does a closing bracket have to close?

Every code editor can instantly tell you whether the brackets in your program match up. Tonight, you are the editor.

Given a string made of the characters ( and ), check if the brackets are balanced - every opening bracket is closed by exactly one closing bracket that comes after it, and every closing bracket closes exactly one opening bracket before it.

For example, (()()) is balanced, while (() is not (an opener was never closed) and )( is not (a closer appeared before any opener).

Input

First line of input will be a single string s, made only of the characters ( and ).

Output

Print YES if the brackets are balanced, and NO otherwise.

Example

Input
(()())
Output
YES

The first bracket is closed by the last one, and the two pairs inside close each other.

Constraints

1≤∣s∣≤106

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit