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

#include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  list<int> li;
  int ignore = 0;

  for (int i = 0; i < n; ++i) {
    string op;
    cin >> op;
    if (op == "insert") {
      int key;
      cin >> key;
      li.push_front(key);
    } else if (op == "delete") {
      int key;
      cin >> key;
      list<int>::iterator pos = find(li.begin(), li.end(), key);
      if (pos != li.end()) {
        li.erase(pos);
      }
    } else if (op == "deleteFirst") {
      li.pop_front();
    } else if (op == "deleteLast") {
      ignore++;
    }
  }

  list<int>::iterator it2 = li.end();
  advance(it2, -ignore);
  for (list<int>::iterator it = li.begin(); it != it2; ++it) {
    cout << ((it == li.begin()) ? "" : " ") << *it;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  list<int> li;
  int first_ignore = 0;
  int last_ignore = 0;

  for (int i = 0; i < n; ++i) {
    string op;
    cin >> op;
    if (op == "insert") {
      int key;
      cin >> key;
      if (first_ignore == 0) {
        li.push_front(key);
      } else {
        first_ignore--;
        list<int>::iterator pos = li.begin();
        advance(pos, first_ignore);
        *pos = key;
      }
    } else if (op == "delete") {
      int key;
      cin >> key;
      list<int>::iterator pos = find(li.begin(), li.end(), key);
      if (pos != li.end()) {
        li.erase(pos);
      }
    } else if (op == "deleteFirst") {
      first_ignore++;
    } else if (op == "deleteLast") {
      last_ignore++;
    }
  }

  list<int>::iterator it1 = li.begin();
  advance(it1, first_ignore);
  list<int>::iterator it2 = li.end();
  advance(it2, -last_ignore);
  for (list<int>::iterator it = it1; it != it2; ++it) {
    cout << ((it == it1) ? "" : " ") << *it;
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  list<long> lis;
  for (int i = 0; i < n; ++i) {
    string ope;
    long key;
    cin >> ope;
    if (ope == "insert") {
      cin >> key;
      lis.push_front(key);
    } else if (ope == "delete") {
      cin >> key;
      list<long>::iterator pos = find(lis.begin(), lis.end(), key);
      if (pos != lis.end()) {
        lis.erase(pos);
      }
    } else if (ope == "deleteFirst") {
      lis.pop_front();
    } else if (ope == "deleteLast") {
      lis.pop_back();
    }
  }
  for (list<long>::iterator it = lis.begin(); it != lis.end(); ++it) {
    cout << ((it == lis.begin()) ? "" : " ") << *it;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  list<long long> lis;
  for (int i = 0; i < n; ++i) {
    string ope;
    long long key;
    cin >> ope;
    if (ope == "insert") {
      cin >> key;
      lis.push_front(key);
    } else if (ope == "delete") {
      cin >> key;
      list<long long>::iterator pos = find(lis.begin(), lis.end(), key);
      if (pos != lis.end()) {
        lis.erase(pos);
      }
    } else if (ope == "deleteFirst") {
      lis.pop_front();
    } else if (ope == "deleteLast") {
      lis.pop_back();
    }
  }
  for (list<long long>::iterator it = lis.begin(); it != lis.end(); ++it) {
    cout << ((it == lis.begin()) ? "" : " ") << *it;
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  // const string
  //   str_insert = "insert",
  //   str_delete = "delete",
  //   str_delete_first = "deleteFirst",
  //   str_delete_last = "deleteLast";

  int N;
  cin >> N;

  list<int> l;
  // typedef enum{INS, DEL, DEL_F, DEL_L}
  // command;

  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;

    // command c;
    if (s[0] == 'i') {
      int n;
      cin >> n;
      l.push_front(n);
      // break;
    } else if (s.size() == 6) {
      int n;
      cin >> n;
      auto itr = find(l.begin(), l.end(), n);
      if (itr != l.end()) {
        l.erase(itr);
      }
      // break;
    } else if (s[6] == 'F') {
      l.pop_front();
      // break;
    } else if (s[6] == 'L') {
      l.pop_back();
      // break;
    }

    // cout << *(l.begin());
    // for(std::list<int>::iterator itr = next(l.begin()); itr!=l.end(); ++itr){
    //   cout << ' ' << *itr;
    // }
    // cout << endl;
  }

  cout << *(l.begin());
  for (std::list<int>::iterator itr = next(l.begin()); itr != l.end(); ++itr) {
    cout << ' ' << *itr;
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  // const string
  //   str_insert = "insert",
  //   str_delete = "delete",
  //   str_delete_first = "deleteFirst",
  //   str_delete_last = "deleteLast";

  int N;
  cin >> N;

  list<int> l;
  // typedef enum{INS, DEL, DEL_F, DEL_L}
  // command;

  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;

    // command c;
    if (s[0] == 'i') {
      int n;
      cin >> n;
      l.push_front(n);
      // break;
    } else if (s.size() == 6) {
      int n;
      cin >> n;
      auto itr = find(l.begin(), l.end(), n);
      if (itr != l.end()) {
        l.erase(itr);
      }
      // break;
    } else if (s[6] == 'F') {
      l.pop_front();
      // break;
    } else if (s[6] == 'L') {
      l.pop_back();
      // break;
    }

    // cout << *(l.begin());
    // for(std::list<int>::iterator itr = next(l.begin()); itr!=l.end(); ++itr){
    //   cout << ' ' << *itr;
    // }
    // cout << endl;
  }

  cout << *(l.begin());
  for (std::list<int>::iterator itr = next(l.begin()); itr != l.end(); ++itr) {
    cout << ' ' << *itr;
  }
  cout << endl;

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

#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

struct Elm {
  int val;
  Elm *prev, *next;
};

Elm *nil;

void newList() {
  nil = (Elm *)malloc(sizeof(Elm));
  nil->next = nil;
  nil->prev = nil;
}

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

void del(Elm *e) {
  if (e == nil)
    return;
  e->prev->next = e->next;
  e->next->prev = e->prev;
  free(e);
}

void dropHead() { del(nil->next); }

void dropLast() { del(nil->prev); }

Elm *find(int val) {
  Elm *cur = nil->next;
  while (cur != nil && cur->val != val)
    cur = cur->next;
  return cur;
}

void remove(int val) { del(find(val)); }

void print() {
  Elm *cur = nil->next;
  while (cur != nil) {
    if (cur->next == nil)
      printf("%d\\n", cur->val);
    else
      printf("%d ", cur->val);
    cur = cur->next;
  }
}

int main() {
  int n, val;
  char order[12];
  scanf("%d", &n);
  newList();

  for (int i = 0; i < n; i++) {
    scanf("%s", order);
    if (order[6] == 'F')
      dropHead();
    else if (order[6] == 'L')
      dropLast();
    else {
      scanf("%d", &val);
      if (order[0] == 'i')
        insert(val);
      else
        remove(val);
    }
  }

  print();
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void printVec(vector<int> l, string delim) {
  string s = "";
  for (int i = 0; i < l.size() - 1; i++)
    s += to_string(l[i]) + delim;
  s += to_string(l[l.size() - 1]) + "\\n";
  cout << s;
}

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

  vector<int> l;

  for (int i = 0; i < n; i++) {
    string c;
    cin >> c;
    if (c == "insert") {
      int v;
      cin >> v;
      l.insert(l.begin(), v);
    } else if (c == "delete") {
      int v;
      cin >> v;
      auto itr = std::find(l.begin(), l.end(), v);
      if (itr == l.end())
        continue;
      size_t pos = distance(l.begin(), itr);
      l.erase(l.begin() + pos);
    } else if (c == "deleteFirst") {
      l.erase(l.begin());
    } else if (c == "deleteLast") {
      l.pop_back();
    } else {
      cout << "input error" << endl;
    }
  }

  printVec(l, " ");

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

class Doublylist {
public:
  Doublylist(int size) : front(0), back(0) { allocate_array = new int[size]; }
  ~Doublylist() { delete[] allocate_array; }
  void delite(int val);
  void print();
  void insert(int val) { allocate_array[front++] = val; }
  void delite_first() { front--; }
  void delite_last() { back++; }

private:
  int front, back;
  int *allocate_array;
};

void Doublylist::delite(int val) {
  for (int i = front - 1; i >= back; i--) {
    if (val == allocate_array[i]) {
      for (int j = i; j < front; j++) {
        allocate_array[j] = allocate_array[j + 1];
      }
      front--;
      return;
    }
  }
}

void Doublylist::print() {
  for (int i = front - 1; i >= back; i--) {
    cout << allocate_array[i];
    if (i == back)
      cout << "\\n";
    else
      cout << " ";
  }
}

int main(void) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  Doublylist li(n);
  for (int i = 0; i < n; i++) {
    string str;
    int val;
    cin >> str;

    if (str == "insert") {
      cin >> val;
      li.insert(val);
    } else if (str == "delete") {
      cin >> val;
      li.delite(val);
    } else if (str == "deleteFirst") {
      li.delite_first();
    } else if (str == "deleteLast") {
      li.delite_last();
    }
  }

  li.print();
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

class Doublylist {
public:
  Doublylist(int size) : front(0), back(0) { allocate_array = new int[size]; }
  ~Doublylist() { delete[] allocate_array; }
  void delite(int val);
  void print();
  void insert(int val) { allocate_array[front++] = val; }
  void delite_first() { front--; }
  void delite_last() { back++; }

private:
  int front, back;
  int *allocate_array;
};

void Doublylist::delite(int val) {
  for (int i = front - 1; i >= back; i--) {
    if (val == allocate_array[i]) {
      for (int j = i; j < front; j++) {
        allocate_array[j] = allocate_array[j + 1];
      }
      front--;
      return;
    }
  }
}

void Doublylist::print() {
  for (int i = front - 1; i >= back; i--) {
    cout << allocate_array[i];
    if (i == back)
      cout << endl;
    else
      cout << " ";
  }
}

int main(void) {
  int n;
  cin >> n;
  Doublylist li(n);
  for (int i = 0; i < n; i++) {
    string str;
    int val;
    cin >> str;

    if (str == "insert") {
      cin >> val;
      li.insert(val);
    } else if (str == "delete") {
      cin >> val;
      li.delite(val);
    } else if (str == "deleteFirst") {
      li.delite_first();
    } else if (str == "deleteLast") {
      li.delite_last();
    }
  }

  li.print();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

typedef struct _List {
  _List *front;
  _List *rear;
  int data;
} List;

int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  string s;
  int d;
  cin >> n;
  List *top;
  List *end;
  List a;
  a.front = NULL;
  a.rear = NULL;
  a.data = 0;
  top = &a;
  end = &a;

  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> d;
      List *temp = new List;

      temp->data = d;
      temp->rear = top;
      temp->front = NULL;
      top->front = temp;
      top = temp;
    } else if (s == "delete") {
      cin >> d;
      List *t = top;

      while (t != NULL && t->rear != NULL) {
        if (t->data == d) {
          if (t->front != NULL)
            (t->front)->rear = (t->rear);
          else
            top = t->rear;
          if (t->rear != NULL)
            (t->rear)->front = (t->front);
          break;
        }
        t = t->rear;
      }
    } else if (s == "deleteFirst") {
      if (top->rear != NULL)
        (top->rear)->front = NULL;
      top = top->rear;
    } else if (s == "deleteLast") {
      List *t = end;

      t = t->front;
      t = t->front;
      if (t != NULL)
        t->rear = end;
      else
        top = end;
      end->front = t;
    }
  }

  List *t = top;
  while (t->rear != NULL) {
    if (t != top)
      cout << " ";
    cout << t->data;
    t = t->rear;
  }
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

typedef struct _List {
  _List *front;
  _List *rear;
  int data;
} List;

int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  string s;
  int d;
  cin >> n;
  List *top;
  List *end;
  List a;
  a.front = NULL;
  a.rear = NULL;
  a.data = 0;
  top = &a;
  end = &a;

  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> d;
      List *temp = new List;

      temp->data = d;
      temp->rear = top;
      temp->front = NULL;
      top->front = temp;
      top = temp;
    } else if (s == "delete") {
      cin >> d;
      List *t = top;

      while (t != NULL && t->rear != NULL) {
        if (t->data == d) {
          if (t->front != NULL)
            (t->front)->rear = (t->rear);
          else
            top = t->rear;
          if (t->rear != NULL)
            (t->rear)->front = (t->front);
          break;
        }
        t = t->rear;
      }
    } else if (s == "deleteFirst") {
      if (top->rear != NULL)
        (top->rear)->front = NULL;
      top = top->rear;
    } else if (s == "deleteLast") {
      List *t = end;

      t = t->front;
      t = t->front;
      t->rear = end;
      end->front = t;
    }
  }

  List *t = top;
  while (t->rear != NULL) {
    if (t != top)
      cout << " ";
    cout << t->data;
    t = t->rear;
  }
  cout << endl;

  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  std::ios_base::sync_with_stdio(false);
  list<int> l;
  string s;
  int d;
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> d;
      l.push_front(d);
    } else if (s == "delete") {
      cin >> d;
      list<int>::iterator pos;
      pos = find(l.begin(), l.end(), d);
      if (pos != l.end())
        l.erase(pos);
    } else if (s == "deleteFirst") {
      l.pop_front();
    } else if (s == "deleteLast") {
      l.pop_back();
    }
  }

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

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  std::ios_base::sync_with_stdio(false);
  list<int> l;
  string s;
  int d;
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> d;
      l.push_front(d);
    } else if (s == "delete") {
      cin >> d;
      list<int>::iterator pos;
      pos = find(l.begin(), l.end(), d);
      l.erase(pos);
    } else if (s == "deleteFirst") {
      l.pop_front();
    } else if (s == "deleteLast") {
      l.pop_back();
    }
  }

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

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

#include <iostream>
#include <list>
using namespace std;

int main(void) {
  std::ios_base::sync_with_stdio(false);
  list<int> l;
  int n;
  string s;
  int d;

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

  list<int>::iterator it = l.begin();
  while (it != l.end()) {
    if (it != l.begin())
      cout << " ";
    cout << *it;
    ++it;
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
using namespace std;

int main(void) {
  list<int> l;
  int n;
  string s;
  int d;

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

  list<int>::iterator it = l.begin();
  while (it != l.end()) {
    if (it != l.begin())
      cout << " ";
    cout << *it;
    ++it;
  }
  cout << endl;

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

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

#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  list<int> l;
  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    if (s[0] == 'i') {
      int x;
      cin >> x;
      l.push_front(x);
    } else {
      if (s[6] == 'F') {
        l.pop_front();
      } else if (s[6] == 'L') {
        l.pop_back();
      } else {
        int x;
        cin >> x;
        for (auto itr = l.begin(); itr != l.end(); ++itr) {
          if (*itr == x) {
            l.erase(itr);
            break;
          }
        }
      }
    }
  }
  int i = 0;

  for (auto itr = l.begin(); itr != l.end(); ++itr) {
    if (i++)
      cout << " ";
    cout << *itr;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

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

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

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

#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  list<int> l;
  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    if (s[0] == 'i') {
      int x;
      cin >> x;
      l.push_front(x);
    } else {
      if (s[6] == 'F') {
        l.pop_front();
      } else if (s[6] == 'L') {
        l.pop_back();
      } else {
        int x;
        cin >> x;
        for (auto itr = l.begin(); itr != l.end(); ++itr) {
          if (*itr == x) {
            l.erase(itr);
            break;
          }
        }
      }
    }
  }
  int i = 0;

  for (auto itr = l.begin(); itr != l.end(); ++itr) {
    if (i++)
      cout << " ";
    cout << *itr;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

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

  for (auto itr = l.begin(); itr != l.end(); ++itr) {
    if (i++)
      cout << " ";
    cout << *itr;
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int n;
list<int> x;

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  rep(i, n) {
    string a;
    cin >> a;
    if (a == "deleteFirst") {
      x.pop_front();
    } else if (a == "deleteLast") {
      x.pop_back();
    } else {
      int b;
      cin >> b;
      if (a == "insert") {
        x.push_front(b);
      } else {
        list<int>::iterator it = find(x.begin(), x.end(), b);
        if (it != x.end()) {
          x.erase(it);
        }
      }
    }
  }
  for (list<int>::iterator it = x.begin(); it != x.end(); ++it) {
    if (it != x.begin()) {
      cout << ' ';
    }
    cout << *it;
  }
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int n;
list<int> x;

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  rep(i, n) {
    string a;
    cin >> a;
    if (a == "deleteFirst") {
      x.pop_front();
    } else if (a == "deleteLast") {
      x.pop_back();
    } else {
      int b;
      cin >> b;
      if (a == "insert") {
        x.push_front(b);
      } else {
        x.erase(find(x.begin(), x.end(), b));
      }
    }
  }
  for (list<int>::iterator it = x.begin(); it != x.end(); ++it) {
    if (it != x.begin()) {
      cout << ' ';
    }
    cout << *it;
  }
  cout << endl;
  return 0;
}