alexjercan/bugnet huggingface dataset:
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node *listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil)
      break;
    if (isf++ > 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\\n");
}

void deleteNode(Node *t) {
  if (t == nil)
    return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() { deleteNode(nil->next); }

void deleteLast() { deleteNode(nil->prev); }

void deleteKey(int key) { deleteNode(listSearch(key)); }

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F')
          deleteFirst();
        else if (com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
      }
    }
  }

  printList();

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define LEN (2000000)

static void insert_num(int k, vector<int> &v) {
  vector<int>::iterator it = v.begin();
  it = v.insert(it, k);
}

static void delete_num(int k, vector<int> &v) {
  vector<int>::iterator it = find(v.begin(), v.end(), k);
  if (it != v.end()) {
    v.erase(it);
  }
}

static void deleteFirst(vector<int> &v) { v.erase(v.begin()); }

static void deleteLast(vector<int> &v) { v.pop_back(); }

int main() {
  int n, k;
  cin >> n;
  vector<string> op(LEN);
  vector<int> v(0, 0);
  for (int i = 0; i < n; i++) {
    cin >> op[i];
    if (op[i] == "insert") {
      cin >> k;
      insert_num(k, v);
    } else if (op[i] == "delete") {
      cin >> k;
      delete_num(k, v);
    } else if (op[i] == "deleteFirst") {
      deleteFirst(v);
    } else if (op[i] == "deleteLast") {
      deleteLast(v);
    } else {
      cout << "no such operator" << endl;
      return -1;
    }
  }

  for (int x : v) {
    cout << x << " ";
  }
  cout << endl;

  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;

  deque<int> dq;
  while (n--) {
    char cum[12];
    int num;
    scanf("%s", cum);
    if (strcmp(cum, "insert") == 0) {
      scanf("%d", &num);
      dq.push_front(num);
    } else if (strcmp(cum, "delete") == 0) {
      scanf("%d", &num);
      bool flag = false;
      deque<int> nxt;
      while (!dq.empty()) {
        int dat = dq.front();
        dq.pop_front();
        if (dat == num && !flag) {
          // cout << dat << endl;
          flag = true;
          continue;
        }
        nxt.push_back(dat);
      }
      dq = nxt;
    } else if (strcmp(cum, "deleteFirst")) {
      dq.pop_back();
    } else {
      dq.pop_front();
    }
  }

  while (dq.size() > 1) {
    printf("%d ", dq.front());
    dq.pop_front();
  }
  if (dq.size())
    cout << dq.front() << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;

  deque<int> dq;
  while (n--) {
    string cum;
    int num;
    cin >> cum;
    if (cum == "insert") {
      cin >> num;
      dq.push_front(num);
    } else if (cum == "delete") {
      cin >> num;
      bool flag = false;
      deque<int> nxt;
      while (!dq.empty()) {
        int dat = dq.front();
        dq.pop_front();
        if (dat == num && !flag) {
          flag = true;
          continue;
        }
        nxt.push_back(dat);
      }
      dq = nxt;
    } else if (cum == "deleteFirst") {
      dq.pop_front();
    } else {
      dq.pop_back();
    }
  }

  while (dq.size() > 1) {
    cout << dq.front() << " ";
    dq.pop_front();
  }
  if (dq.size())
    cout << dq.front() << endl;

  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  int i, j;
  int n;
  int x;
  char command[16];
  list<int> l;
  list<int>::iterator it_l; // lのイテレータ作成

  // fgets(command,16,stdin);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s%d", command, &x);
    if (command[0] == 'i') {
      // cin >> x;
      l.push_front(x);
    } else if (command[0] == 'd' && command[6] == '\\0') {
      // cin >> x;
      it_l = l.begin(); // lのイテレータを最初の要素に合わせる
      while (it_l != l.end()) { // ｘをもつ最初の要素（ノード）を探して削除
        if ((*it_l) == x) {
          l.erase(it_l);
          break;
          /*このbreakが大切。　要素を消した後は、その要素で it_l++ すると　
          「list iterator not incrementable」が出てできない
          消した後も探索したい場合は、消す前にほかのに保存して
          イテレーターを進めておくこと。
          */
        }
        it_l++;
      }
    } else if (command[0] == 'd' && command[6] == 'F') {
      l.pop_front();
    } else if (command[0] == 'd' && command[6] == 'L') {
      l.pop_back();
    }
    // else {cout << "error" << endl; }
  }

  // 出力普通版
  /*
  it_l = l.begin(); // lのイテレータを最初の要素に合わせる
while(it_l != l.end()){ //出力
  cout << *it_l;
  it_l++;
  if(it_l == l.end()){ //悪い書き方。　だが適切な改行を出すのにこれが簡単
      cout << endl;
      break;
  }
  cout << ' ';
}
  */

  // 出力三項演算子版
  it_l = l.begin(); // lのイテレータを最初の要素に合わせる
  while (it_l != l.end()) { // 出力
    printf("%d", *it_l);    // cout << *it_l;
    it_l++;
    (it_l == l.end()) ? printf("\\n") : printf(" ");
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <string>

using namespace std;

int main() {
  int i, j;
  int n;
  int x;
  string command;
  list<int> l;
  list<int>::iterator it_l; // lのイテレータ作成

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> command;
    if (command == "insert") {
      cin >> x;
      l.push_front(x);
    } else if (command == "delete") {
      cin >> x;
      it_l = l.begin(); // lのイテレータを最初の要素に合わせる
      while (it_l != l.end()) { // ｘをもつ最初の要素（ノード）を探して削除
        if ((*it_l) == x) {
          l.erase(it_l);
          break;
          /*このbreakが大切。　要素を消した後は、その要素で it_l++ すると　
          「list iterator not incrementable」が出てできない
          消した後も探索したい場合は、消す前にほかのに保存して
          イテレーターを進めておくこと。
          */
        }
        it_l++;
      }
    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
    // else {cout << "error" << endl; }
  }

  /*
  it_l = l.begin(); // lのイテレータを最初の要素に合わせる
while(it_l != l.end()){ //出力
  cout << *it_l;
  it_l++;
  if(it_l == l.end()){ //悪い書き方。　だが適切な改行を出すのにこれが簡単
      cout << endl;
      break;
  }
  cout << ' ';
}
  */

  it_l = l.begin(); // lのイテレータを最初の要素に合わせる
  while (it_l != l.end()) { // 出力
    cout << *it_l;
    it_l++;
    (it_l == l.end()) ? (cout << endl) : (cout << ' ');
  }

  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <string>

int main() {
  std::list<int> list;
  int n;
  std::cin >> n;
  std::string command;
  for (int i = 0; i < n; i++) {
    std::cin >> command;
    if (command[0] == 'i') {
      int x;
      std::cin >> x;
      list.push_front(x);
    } else if (command[6] == 'F') {
      list.pop_front();
    } else if (command[6] == 'L') {
      list.pop_back();
    } else if (command[0] == 'd') {
      int x;
      std::cin >> x;
      for (auto i = list.begin(); i != list.end(); i++) {
        if (*i == x) {
          list.erase(i);
          break;
        }
      }
    }
  }

  auto i = list.begin();
  std::cout << *i;
  for (i++; i != list.end(); i++) {
    std::cout << " " << *i;
  }
  std::cout << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <string>

int main() {
  std::list<int> list;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::string command;
    std::cin >> command;
    if (command == "insert") {
      int x;
      std::cin >> x;
      list.push_front(x);
    } else if (command == "delete") {
      int x;
      std::cin >> x;
      for (auto i = list.begin(); i != list.end(); i++) {
        if (*i == x) {
          list.erase(i);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      list.pop_front();
    } else if (command == "deleteLast") {
      list.pop_back();
    }
  }

  auto i = list.begin();
  std::cout << *i;
  for (i++; i != list.end(); i++) {
    std::cout << " " << *i;
  }
  std::cout << std::endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  list<int> v;

  int n;
  for (cin >> n; n--;) {
    char c[20];
    int x;
    scanf("%s", c);

    string s = c;

    if (s == "insert") {
      scanf("%d", &x);
      v.push_front(x);
    } else if (s == "delete") {
      scanf("%d", &x);
      for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (*it == x) {
          v.erase(it);
          break;
        }
      }
    } else if (s == "deleteFirst") {
      v.pop_front();
    } else if (s == "deleteLast") {
      v.pop_back();
    }
  }

  bool space = false;
  for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << (space ? " " : "");
    space = true;

    cout << *it;
  }

  cout << endl;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  list<int> v;

  int n;
  for (cin >> n; n--;) {
    string s;
    int x;
    cin >> s;

    if (s == "insert") {
      cin >> x;
      v.push_front(x);
    } else if (s == "delete") {
      cin >> x;
      for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (*it == x) {
          v.erase(it);
          break;
        }
      }
    } else if (s == "deleteFirst") {
      v.pop_front();
    } else if (s == "deleteLast") {
      v.pop_back();
    }
  }

  bool space = false;
  for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << (space ? " " : "");
    space = true;

    cout << *it;
  }

  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <list>
using namespace std;

int main() {
  int n;
  list<int> L;
  char str[15];
  scanf("%d", &n);
  for (int i = 0, num; i < n; i++) {
    scanf("%s", str);
    if (str[0] == 'i') {
      scanf("%d", &num);
      L.push_front(num);
    } else if (str[6] == 'F') {
      L.pop_front();
    } else if (str[6] == 'L') {
      L.pop_back();
    } else {
      scanf("%d", &num);
      for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
        if (*it == num) {
          L.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
    if (i++)
      printf(" ");
    printf("%d", *it);
  }
  printf("\\n");
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <list>
using namespace std;

int main() {
  int n;
  list<int> L;
  string str;
  cin >> n;
  for (int i = 0, num; i < n; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> num;
      L.push_front(num);
    } else if (str == "delete") {
      cin >> num;
      for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
        if (*it == num) {
          L.erase(it);
          break;
        }
      }
    } else if (str == "deleteFirst") {
      L.pop_front();
    } else if (str == "deleteLast") {
      L.pop_back();
    }
  }
  int i = 0;
  for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
    if (i++)
      cout << " ";
    cout << *it;
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>

#include <algorithm>
#include <deque>
#include <iostream>
#include <string>

using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  deque<int> l;
  while (n--) {
    string s;
    cin >> s;
    if (s == "insert") {
      int x;
      cin >> x;
      l.push_front(x);
    } else if (s == "delete") {
      int x;
      cin >> x;
      auto it = find(l.begin(), l.end(), x);
      if (it != l.end()) {
        l.erase(it);
      }
    } else if (s == "deleteFirst") {
      l.pop_front();
    } else if (s == "deleteLast") {
      l.pop_back();
    } else {
      assert(false);
    }
  }

  int k = 0;
  for (int item : l) {
    cout << item << " \\n"[k++ == l.size() - 1];
  }
}

Error: TLE

Fixed submission:

#include <cassert>

#include <algorithm>
#include <deque>
#include <iostream>
#include <string>

using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

int main() {
  int n;
  cin >> n;
  deque<int> l;
  while (n--) {
    string s;
    cin >> s;
    if (s == "insert") {
      int x;
      cin >> x;
      l.push_front(x);
    } else if (s == "delete") {
      int x;
      cin >> x;
      auto it = find(l.begin(), l.end(), x);
      if (it != l.end()) {
        l.erase(it);
      }
    } else if (s == "deleteFirst") {
      l.pop_front();
    } else if (s == "deleteLast") {
      l.pop_back();
    } else {
      assert(false);
    }
  }

  int k = 0;
  for (int item : l) {
    cout << item << " \\n"[k++ == l.size() - 1];
  }
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp*/

#include <algorithm>
#include <iostream>
#include <list>

using namespace std;

int main() {
  int n;
  list<int> data;
  string command;
  int value;
  list<int>::iterator it;

  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command == "deleteFirst") {
      data.pop_front();
    } else if (command == "deleteLast") {
      data.pop_back();
    } else {
      cin >> value;
      if (command == "insert") {
        data.push_front(value);
      } else {
        it = find(data.begin(), data.end(), value);
        if (it != data.end()) {
          data.erase(it);
        }
      }
    }
  }
  it = data.begin();
  while (it != data.end()) {
    cout << *it++;
    if (it != data.end()) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp*/

#include <algorithm>
#include <iostream>
#include <list>

using namespace std;

int main() {
  int n;
  list<int> data;
  string command;
  int value;
  list<int>::iterator it;

  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command == "deleteFirst") {
      data.pop_front();
    } else if (command == "deleteLast") {
      data.pop_back();
    } else {
      cin >> value;
      if (command == "insert") {
        data.push_front(value);
      } else {
        it = find(data.begin(), data.end(), value);
        if (it != data.end()) {
          data.erase(it);
        }
      }
    }
  }
  while (0 < data.size()) {
    cout << data.front();
    if (1 < data.size()) {
      cout << " ";
    }
    data.pop_front();
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <deque>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  deque<int> que;
  for (int i = 0; i < n; i++) {
    string order;
    int value;
    cin >> order;
    if (order == "deleteFirst" || order == "deleteLast") {
      if (order == "deleteFirst")
        que.pop_front();
      else
        que.pop_back();
      continue;
    }
    cin >> value;
    if (order == "insert") {
      que.push_front(value);
    } else {
      for (auto itr = que.begin(); itr != que.end(); ++itr) {
        if (*itr == value) {
          que.erase(itr);
          break;
        }
      }
    }
  }

  for (auto itr = que.begin(); itr < que.end() - 1; itr++) {
    cout << *itr << " ";
  }
  cout << que.back() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <deque>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  deque<int> que;
  for (int i = 0; i < n; i++) {
    string order;
    int value;
    cin >> order;
    if (order == "deleteFirst" || order == "deleteLast") {
      if (order == "deleteFirst")
        que.pop_front();
      else
        que.pop_back();
      continue;
    }
    cin >> value;
    if (order == "insert") {
      que.push_front(value);
    } else {
      for (auto itr = que.begin(); itr != que.end(); itr++) {
        if (*itr == value) {
          que.erase(itr);
          break;
        }
      }
    }
  }

  for (auto itr = que.begin(); itr < que.end() - 1; itr++) {
    cout << *itr << " ";
  }
  cout << que.back() << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, n) for (int i = (a); i > n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
  int n;
  cin >> n;
  list<int> li;
  string s;
  int x;
  rep(i, 0, n) {
    cin >> s;
    if (s == "insert") {
      cin >> x;
      li.push_front(x);
    } else if (s == "delete") {
      cin >> x;
      for (list<int>::iterator it = li.begin(); it != li.end(); ++it)
        if (*it == x) {
          li.erase(it);
          break;
        }
    } else if (s == "deleteFirst") {
      li.pop_front();
    } else if (s == "deleteLast") {
      li.pop_back();
    }
  }
  vi v(all(li));
  int len_v = len(v);
  rep(i, 0, len_v) cout << v[i] << (i + 1 == len_v ? "\\n" : " ");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, n) for (int i = (a); i > n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
  int n;
  cin >> n;
  list<int> li;
  string s;
  int x;
  rep(i, 0, n) {
    cin >> s;
    if (s == "insert") {
      cin >> x;
      li.push_front(x);
    }
    if (len(li) == 0)
      continue;
    if (s == "delete") {
      cin >> x;
      list<int>::iterator it = li.begin();
      while (it != li.end()) {
        if (*it == x) {
          it = li.erase(it);
          break;
        } else
          ++it;
      }
    }
    if (s == "deleteFirst") {
      li.pop_front();
    } else if (s == "deleteLast") {
      li.pop_back();
    }
  }
  vi v(all(li));
  int len_v = len(v);
  rep(i, 0, len_v) cout << v[i] << (i + 1 == len_v ? "\\n" : " ");
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <string>

int main() {

  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  std::cin >> n;
  std::list<int> l;

  for (int i = 0; i < n; i++) {
    std::string op;
    int x;
    std::cin >> op;
    if (op == "insert" || op == "delete")
      std::cin >> x;

    if (op == "insert")
      l.push_front(x);
    else if (op == "deleteFirst")
      l.pop_front();
    else if (op == "deleteLast")
      l.pop_back();
    else if (op == "delete") {
      std::list<int>::iterator i = std::find(l.begin(), l.end(), x);
      if (i != l.end())
        l.erase(i);
    }
  }

  for (std::list<int>::iterator i = l.begin(); i != l.end(); ++i) {
    if (++i != l.end())
      std::cout << *(--i) << " ";
    else
      std::cout << *(--i) << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <string>

int main() {
  int n;
  std::cin >> n;
  std::list<int> l;
  for (int i = 0; i < n; i++) {
    std::string op;
    int x;
    std::cin >> op;
    if (op == "insert" || op == "delete")
      std::cin >> x;

    if (op == "insert")
      l.push_front(x);
    else if (op == "deleteFirst")
      l.pop_front();
    else if (op == "deleteLast")
      l.pop_back();
    else if (op == "delete") {
      std::list<int>::iterator i = std::find(l.begin(), l.end(), x);
      if (i != l.end())
        l.erase(i);
    }
  }

  for (std::list<int>::iterator i = l.begin(); i != l.end(); ++i) {
    if (++i != l.end())
      std::cout << *(--i) << " ";
    else
      std::cout << *(--i) << std::endl;
  }

  return 0;
}