#include using namespace std; int main() { int N; cin >> N; deque dq; for(int i=0; i> T >> c; if(T == 0) dq.push_back(c); else dq.push_front(c); } for(int i=0; i