Brackets

Given a bracket string, decide whether flipping the brackets in at most one contiguous segment can turn the whole string into a balanced, valid bracket sequence.

Medium6GreedyPrefix sumStringImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A bracket sequence made of ( and ) is valid exactly when the following rules build it.

  1. The empty sequence is valid.
  2. If XX is a valid bracket sequence, then (X)(X) is a valid bracket sequence.
  3. If XX and YY are valid bracket sequences, then their concatenation Z=XYZ = XY is a valid bracket sequence.

For example, (()), ()(), and (()())() are valid bracket sequences, while ( and ()) are not.

You are given a bracket sequence of length nn. It might not be valid. Decide whether at most one segment inversion makes it a valid bracket sequence. A segment inversion picks two 1-based indices ll and rr (1lrn1 \le l \le r \le n) and inverts every bracket at an index in the closed interval [l,r][l, r]. After the inversion, a left bracket ( becomes a right bracket ), and a right bracket ) becomes a left bracket (.

Inverting the segment [3,4][3, 4] makes ())( valid. Inverting the segment [3,3][3, 3] makes ())) valid, and inverting the segment [2,2][2, 2] does the same. No segment inversion makes )))( valid.

Input

One line holds the bracket sequence. Its length is between 1 and 5000, and it contains only ( and ).

Output

Print possible if at most one segment inversion makes the bracket sequence valid, and impossible otherwise.