1 | #include<bits/stdc++.h> |
2 | using namespace std; |
3 | const int M=1e6+10; |
4 | deque<int>dq[M]; |
5 | int main() |
6 | { |
7 | int q; |
8 | cin>>q; |
9 | while(q--) |
10 | { |
11 | string op; |
12 | cin>>op; |
13 | if(op=="push_back") |
14 | { |
15 | int a,x; |
16 | cin>>a>>x; |
17 | dq[a].push_back(x); |
18 | } |
19 | else if(op=="pop_back") |
20 | { |
21 | int a; |
22 | cin>>a; |
23 | if(!dq[a].empty()) |
24 | { |
25 | dq[a].pop_back(); |
26 | } |
27 | } |
28 | else if(op=="push_front") |
29 | { |
30 | int a,x; |
31 | cin>>a>>x; |
32 | dq[a].push_front(x); |
33 | } |
34 | else if(op=="pop_front") |
35 | { |
36 | int a; |
37 | cin>>a; |
38 | if(!dq[a].empty()) |
39 | { |
40 | dq[a].pop_front(); |
41 | } |
42 | } |
43 | else if(op=="size") |
44 | { |
45 | int a; |
46 | cin>>a; |
47 | cout<<dq[a].size()<<endl; |
48 | } |
49 | else if(op=="front") |
50 | { |
51 | int a; |
52 | cin>>a; |
53 | if(!dq[a].empty()) |
54 | { |
55 | cout<<dq[a].front()<<endl; |
56 | } |
57 | } |
58 | else if(op=="back") |
59 | { |
60 | int a; |
61 | cin>>a; |
62 | if(!dq[a].empty()) |
63 | { |
64 | cout<<dq[a].back()<<endl; |
65 | } |
66 | } |
67 | } |
68 | return 0; |
69 | } |