#include using namespace std; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n; deque ds; for(Int i=0;i>t>>c; if(t==0) ds.emplace_back(c); if(t==1) ds.emplace_front(c); } for(char c:ds) cout<