Under construction

Still being built. Things may change

Mirror Brackets

Interview

Time limit1sMemory limit1024 MB

Summary
Given a string of mirror letters and brackets, apply the reflections until no brackets remain and print the final string.
Level

Medium5 of 10

Topics
Stack, String, Simulation
Solved
No attempts yet

Problem

Let's recall what a correct bracket sequence (CBS) is.

  • An empty string is a CBS.
  • If ss is a CBS, then (ss) and [ss] are also CBS.
  • If ss and tt are CBS, then stst is also a CBS.
  • A sequence that cannot be obtained by the rules above is not a CBS.

Vasya wrote a correct bracket sequence using the brackets "(", ")", "[" and "]". Then he inserted some of the characters "b", "d", "o", "p", "q" and "x" at various places in the sequence, which produced a string zz.

Vasya repeats the following operations.

If zz contains a substring of the form (ss) (where ss has no brackets), he replaces it with the mirror reflection of ss across the vertical axis. If zz contains a substring of the form [tt] (where tt has no brackets), he replaces it with the mirror reflection of tt across the horizontal axis. For example, the substring "(qbpoxd)" becomes "bxoqdp", and the substring "[qbpoxd]" becomes "dpboxq".

Vasya keeps performing these operations until no brackets remain. Given zz, find the final string.

Input

The only line contains the string zz, whose length does not exceed 10510^5. The string consists of the characters "(", ")", "[", "]", "b", "d", "o", "p", "q" and "x". It is guaranteed that the brackets in zz form a correct bracket sequence. It is also guaranteed that the input contains at least one letter.

Output

Print the final string that Vasya gets.

Examples2

  1. Example 1

    Input
    (qbpoxd)[qbpoxd]
    
    Expected output
    bxoqdpdpboxq
    
  2. Example 2

    Input
    d[xd(bx)op]q()[]xx
    
    Expected output
    dxqxqobqxx