#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <memory>
#include <set>
#include <random>

// std::mt19937 rsk(0315);
std::vector<intmax_t> rnd;
constexpr intmax_t mod = 1e9+9;
constexpr double eps = 1e-7;

class tree {
  struct M_node {
    using base_ptr = std::shared_ptr<M_node>;
    base_ptr left = nullptr;
    base_ptr right = nullptr;
    base_ptr parent = nullptr;
    double value = 0.0;
    size_t height = 0;
    intmax_t hash = 1;
    std::set<intmax_t> subtree;  // hashes
    M_node() = default;
    ~M_node() = default;
  };
  using base_ptr = std::shared_ptr<M_node>;

  base_ptr M_root = nullptr;

  base_ptr M_parse(std::string const& s, size_t& i) {
    base_ptr res(new M_node);
    if (s[i] == 'x') {
      ++i;
      res->subtree.insert(1);
      return res;
    }

    assert(s[i] == '(');
    res->left = M_parse(s, ++i);
    res->left->parent = res;
    assert(s[i] == ' ');
    res->right = M_parse(s, ++i);
    res->right->parent = res;
    assert(s[i] == ')');
    ++i;

    res->height = std::max(res->left->height, res->right->height) + 1;
    intmax_t r = rnd[res->height];
    res->hash = (r + res->left->hash) * (r + res->right->hash) % mod;
    for (auto x: res->left->subtree) res->subtree.insert(x);
    int sim = 0;
    for (auto x: res->right->subtree) {
      if (res->subtree.count(x)) {
        ++sim;
      } else {
        res->subtree.insert(x);
      }
    }
    res->value = static_cast<double>(sim) / static_cast<double>(res->subtree.size());
    res->subtree.insert(res->hash);
    assert(res);
    return res;
  }

  static int S_compare(base_ptr lhs, base_ptr rhs) {
    assert(lhs);
    assert(rhs);
    // fprintf(stderr, "%p/%p\n", lhs.get(), rhs.get());
    if (std::abs(lhs->value - rhs->value) > eps)
      return ((lhs->value < rhs->value)? -1: +1);

    if (!lhs->left && !rhs->left) return 0;
    assert(lhs->right);
    assert(rhs->right);

    int cl = S_compare(lhs->left, lhs->right);
    int cr = S_compare(rhs->left, rhs->right);
    base_ptr l1 = ((cl > 0)? lhs->right: lhs->left);
    base_ptr r1 = ((cr > 0)? rhs->right: rhs->left);
    int c = S_compare(l1, r1);
    if (c) return c;

    base_ptr l0 = ((cl > 0)? lhs->left: lhs->right);
    base_ptr r0 = ((cr > 0)? rhs->left: rhs->right);
    return S_compare(l0, r0);
  }

  static void S_normalize_dfs(base_ptr root) {
    if (!root->left) return;
    assert(root->right);

    bool left_strong = (!root->parent || root == root->parent->left);
    int c = S_compare(root->left, root->right);
    if (c != 0) {
      if (left_strong ^ (c < 0)) root->left.swap(root->right);
    }
    S_normalize_dfs(root->left);
    S_normalize_dfs(root->right);
  }

  static void S_dump_dfs(base_ptr root) {
    if (!root->left) {
      putchar('x');
      return;
    }
    assert(root->right);
    putchar('(');
    S_dump_dfs(root->left);
    putchar(' ');
    S_dump_dfs(root->right);
    putchar(')');
  }

  static void S_inspect_dfs(base_ptr root) {
    if (!root->left) {
      fputc('x', stderr);
      fprintf(stderr, "[%jd:%p]", root->hash, root.get());
      return;
    }
    assert(root->right);
    fprintf(stderr, "(%p", root->left.get());
    S_inspect_dfs(root->left);
    fputc(' ', stderr);
    S_inspect_dfs(root->right);
    fprintf(stderr, "%p)", root->right.get());
    fprintf(stderr, "[%jd:%p]", root->hash, root.get());
  }

public:
  tree(std::string const& s) {
    size_t i = 0;
    M_root = M_parse(s, i);
    assert(i == s.length());
    // fprintf(stderr, "%jd\n", M_root->hash);
  }

  void normalize() { S_normalize_dfs(M_root); }
  void dump() const { S_dump_dfs(M_root); putchar('\n'); }
  void inspect() const { S_inspect_dfs(M_root); fputc('\n', stderr); }
};

int testcase_ends() {
  static size_t nc = 0;
  ++nc;

  static char buf[131072];
  fgets(buf, sizeof buf, stdin);
  std::string s = buf;
  // fprintf(stderr, "%zu: %s\n", nc, s.c_str());
  if (s.back() == '\n') s.pop_back();
  assert(!isspace(s.back()));
  if (s == "0") return 1;

  tree t(s);
  // t.inspect();
  // fprintf(stderr, "t(s);");
  t.normalize();
  // fprintf(stderr, "t.normalize();");
  t.dump();
  // fprintf(stderr, "t.dump();");
  // fprintf(stderr, "%zu\n", nc);
  return 0;
}

int main() {
  size_t n = 128;
  rnd.resize(n);
  
  // std::uniform_int_distribution<intmax_t> uni(0, mod-1);
  // for (size_t i = 1; i < n; ++i) rnd[i] = uni(rsk);
  rnd[0] = 1;
  for (size_t i = 1; i < n; ++i) rnd[i] = (rnd[i-1] * 3) % mod;
    
  while (!testcase_ends()) {}
}



Measured memory_bytes: 7964