Tesla's Current
hard
Inventor Nikola has just completed his newest device for harnessing electromagnetic wavelengths! In his eagerness to witness its operation, he hastily arranged the conductive pathways without proper planning and immediately began testing. Shortly after, Nikola discovered that the pathways had become crisscrossed and require rearrangement.
The mechanism functions via two essential pathways: the "active" and "neutral" conductors. These conductors extend across the laboratory floor from the power source (on the left side) to the mechanism (on the right side). Both the source and mechanism feature dual connection terminals at identical heights, where the conductors attach in a particular arrangement. The conductors are considered entangled whenever one passes over the other. The diagram below shows four such intersections (viewed from above):
Nikola has recorded the exact sequence of these overlaps. He's noted that at the source side, the "active" conductor consistently connects to the upper terminal (as shown). His objective is to untangle these conductors without disconnecting them and without shifting the mechanism. While a conductor can be freely repositioned and extended across the laboratory floor, it cannot be severed.
Determine whether his objective is achievable.
Input Format:
A single line containing a sequence of characters "+" and "-" of length n (1≤n≤1000000). The ith position (1≤i≤n) contains "+" if at the ith interval from the source the "active" conductor passes above the "neutral" conductor, and "-" otherwise. Output Format:
Display either "Yes" if the conductors can be untangled or "No" if they cannot.
Examples: