fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  7. #define int ll
  8. #define ll long long
  9. #define ld long double
  10. #define Euler ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  11. #define test ll t; cin>>t; while(t--)
  12. #define all(x) x.begin(), x.end()
  13. #define rall(x) x.rbegin(), x.rend()
  14. #define ys cout<<"YES"<<endl
  15. #define no cout<<"NO"<<endl
  16. #define endl "\n"
  17. #define rv(x) return void(x)
  18. ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b;}
  19. ll lcm(ll a, ll b) { return (abs ((a*b))/ gcd(a,b));}
  20. bool compare(const pair<int, int>&i, const pair<int, int>&j){return (i.first == j.first)? i.second > j.second: i.first < j.first;}
  21. bool comp (const pair<int,pair<int,int>>&i,const pair<int,pair<int,int>>&j){return i.second.first<j.second.first;}
  22. bool pairs(const pair<int,int>&i,const pair<int,int>&j){return i.second>j.second;}
  23. //int dx[] = { 0, 0, 1, -1};
  24. //int dy[] = { -1, 1, 0, 0 };
  25. //int Dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
  26. //int Dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
  27. //const int MOD = 1000000007;
  28. void sol() {
  29. int n;cin>>n;
  30. string s;
  31. deque<int>arr;
  32. bool flag= false;
  33. while (n--){
  34. cin>>s;
  35. if (s=="toFront"){
  36. if (flag){
  37. int x;cin>>x;
  38. arr.push_back(x);
  39. } else{
  40. int x;cin>>x;
  41. arr.push_front(x);
  42. }
  43. } else if (s=="push_back"){
  44. if (flag){
  45. int x;cin>>x;
  46. arr.push_front(x);
  47. } else{
  48. int x;cin>>x;
  49. arr.push_back(x);
  50. }
  51. } else if (s=="front"){
  52. if (!arr.empty()){
  53. if (flag){
  54. cout<<arr.back()<<endl;
  55. arr.pop_back();
  56. } else{
  57. cout<<arr.front()<<endl;
  58. arr.pop_front();
  59. }
  60. } else{
  61. cout<<"No job for Ada?"<<endl;
  62. }
  63. }
  64. else if (s=="back"){
  65. if (!arr.empty()){
  66. if (flag){
  67. cout<<arr.front()<<endl;
  68. arr.pop_front();
  69. } else{
  70. cout<<arr.back()<<endl;
  71. arr.pop_back();
  72. }
  73. } else{
  74. cout<<"No job for Ada?"<<endl;
  75. }
  76. } else{
  77. flag=!flag;
  78. }
  79. }
  80. }
  81. signed main() {
  82. Euler
  83. // freopen("breedflip.in", "r", stdin);
  84. // freopen("breedflip.out", "w", stdout);
  85. // test
  86. sol();
  87. return 0;
  88. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty