#include<bits/stdc++.h> usingnamespace std; intmain(){ ios_base::sync_with_stdio(false); cin.tie(NULL); string s; while(getline(cin, s)){ list<char> l; auto it = l.begin(); for(char c : s){ if(c == '[') it = l.begin(); elseif(c == ']') it = l.end(); else l.insert(it, c); // it will automaticly point to next after insertion, we don't need to manually add ++it } for(char c : l){ cout << c; } cout << '\n'; } return0; }