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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    list<int> li;
    list<int>::iterator it;
    char str[20];
    int inp;
    while (n--) {
      scanf("%s", str);
      if (str[0] == 'i') {
        scanf("%d", &inp);
        li.push_front(inp);
      } else if (str[6] == 'F') {
        li.pop_front();
      } else if (str[6] == 'L') {
        li.pop_back();
      } else if (str[0] == 'd') {
        scanf("%d", &inp);
        for (it = li.begin(); it != li.end(); it++) {
          if (*it == inp) {
            li.erase(it);
            break;
          }
        }
      }
    }
    for (it = li.begin(); it != li.end(); it++) {
      if (it == li.begin())
        cout << *it;
      else
        cout << ' ' << *it;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    list<int> li;
    list<int>::iterator it;
    while (n--) {
      string str;
      int inp;
      cin >> str;
      if (str == "insert") {
        scanf("%d", &inp);
        li.push_front(inp);
      } else if (str == "delete") {
        scanf("%d", &inp);
        for (it = li.begin(); it != li.end(); it++) {
          if (*it == inp) {
            li.erase(it);
            break;
          }
        }
      } else if (str == "deleteFirst") {
        li.pop_front();
      } else if (str == "deleteLast") {
        li.pop_back();
      }
    }
    for (it = li.begin(); it != li.end(); it++) {
      if (it == li.begin())
        cout << *it;
      else
        cout << ' ' << *it;
    }
    cout << endl;
  }
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string>

using namespace std;
struct point {
  int key;
  point *l, *r;
};

int N;
point *nil;
void init() {
  nil = (point *)malloc(sizeof(point));
  nil->l = nil;
  nil->r = nil;
}

void insert(int k) {
  point *p;
  p = (point *)malloc(sizeof(point));
  ;
  p->key = k;
  nil->r->l = p;
  p->r = nil->r;
  nil->r = p;
  p->l = nil;
}

point *find(int k) {
  point *p = nil->r;
  while (p->key != k && p != nil) {
    p = p->r;
  }
  return p;
}

void ddelete(point *p, int k) {
  if (p->key == k) {
    p->r->l = p->l;
    p->l->r = p->r;
    free(p);
  } else
    return;
}

void deletefirst() { ddelete(nil->r, nil->r->key); }

void deletelast() { ddelete(nil->l, nil->l->key); }

int main() {
  cin >> N;
  string s;
  int k;
  init();
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s[0] == 'i') {
      cin >> k;
      insert(k);
    } else if (s[0] == 'd' && s[6] == 'F') {
      deletefirst();
    } else if (s[0] == 'd' && s[6] == 'L') {
      deletelast();
    } else {
      cin >> k;
      ddelete(find(k), k);
    }
  }
  point *p = nil->r;
  while (p->r != nil) {
    cout << p->key << ' ';
    p = p->r;
  }
  if (p != nil) {
    cout << p->key << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string>

using namespace std;
struct point {
  int key;
  point *l, *r;
};

int N;
point *nil;
void init() {
  nil = (point *)malloc(sizeof(point));
  nil->l = nil;
  nil->r = nil;
}

void insert(int k) {
  point *p;
  p = (point *)malloc(sizeof(point));
  ;
  p->key = k;
  nil->r->l = p;
  p->r = nil->r;
  nil->r = p;
  p->l = nil;
}

point *find(int k) {
  point *p = nil;
  while (p->key != k) {
    p = p->r;
  }
  return p;
}

void ddelete(point *p) {
  p->r->l = p->l;
  p->l->r = p->r;
  free(p);
}

void deletefirst() { ddelete(nil->r); }

void deletelast() { ddelete(nil->l); }

int main() {
  cin >> N;
  string s;
  int k;
  init();
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s[0] == 'i') {
      cin >> k;
      insert(k);
    } else if (s[0] == 'd' && s[6] == 'F') {
      deletefirst();
    } else if (s[0] == 'd' && s[6] == 'L') {
      deletelast();
    } else {
      cin >> k;
      ddelete(find(k));
    }
  }
  point *p = nil->r;
  while (p->r != nil) {
    cout << p->key << ' ';
    p = p->r;
  }
  if (p != nil) {
    cout << p->key << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main() {
  std::list<long long> list;
  int n;
  long long p;
  string str;
  std::list<long long>::iterator itr, l;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> p;
      list.push_front(p);
    } else if (str == "deleteFirst")
      list.pop_front();
    else if (str == "deleteLast")
      list.pop_back();
    else {
      cin >> p;
      for (itr = list.begin(), l = list.end(); itr != l; ++itr) {
        if (*itr == p) {
          list.erase(itr);
          break;
        }
      }
    }
  }
  for (itr = list.begin(), l = --list.end(); itr != l; ++itr)
    cout << *itr << " ";
  cout << *itr << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
using namespace std;

int main() {
  std::list<long long> list;
  int n;
  long long p;
  string str;
  std::list<long long>::iterator itr, l;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> p;
      list.push_front(p);
    } else if (str == "deleteFirst")
      list.pop_front();
    else if (str == "deleteLast")
      list.pop_back();
    else {
      cin >> p;
      itr = list.begin();
      for (itr = list.begin(), l = --list.end(); itr != l; ++itr) {
        if (*itr == p)
          list.erase(itr);
      }
    }
  }
  for (itr = list.begin(), l = --list.end(); itr != l; ++itr)
    cout << *itr << " ";
  cout << *itr << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

list<int>::iterator find_key(list<int> &li, int key) {
  list<int>::iterator li_itr = li.begin();
  while (li_itr != li.end()) {
    if (*li_itr == key) {
      return li_itr;
    }
    ++li_itr;
  }
  return li.end();
}

int main(void) {
  ios::sync_with_stdio(false);

  int n;
  list<int> li;

  cin >> n;
  for (int i = 0; i < n; i++) {
    string command;
    cin >> command;

    int key;
    if (command == "insert") {
      cin >> key;
      li.push_front(key);
    } else if (command == "deleteFirst") {
      li.pop_front();
    } else if (command == "deleteLast") {
      li.pop_back();
    } else {
      cin >> key;
      list<int>::iterator erace_itr = find_key(li, key);
      if (erace_itr != li.end()) {
        li.erase(find_key(li, key));
      }
    }
  }

  list<int>::iterator itr = li.begin();
  while (itr != li.end()) {
    cout << *itr;
    ++itr;
    itr == li.end() ? cout << "" : cout << " ";
  }
  cout << endl;
}

Error: 0

Fixed submission:

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

list<int>::iterator find_key(list<int> &li, int key) {
  list<int>::iterator li_itr = li.begin();
  while (li_itr != li.end()) {
    if (*li_itr == key) {
      return li_itr;
    }
    ++li_itr;
  }
  return li.end();
}

int main(void) {
  ios::sync_with_stdio(false);

  int n;
  list<int> li;

  cin >> n;
  for (int i = 0; i < n; i++) {
    string command;
    cin >> command;

    int key;
    if (command == "insert") {
      cin >> key;
      li.push_front(key);
    } else if (command == "deleteFirst") {
      li.pop_front();
    } else if (command == "deleteLast") {
      li.pop_back();
    } else {
      cin >> key;
      li.erase(find_key(li, key));
    }
  }

  list<int>::iterator itr = li.begin();
  while (itr != li.end()) {
    cout << *itr;
    ++itr;
    itr == li.end() ? cout << "" : cout << " ";
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

struct Node {
  Node *prev;
  Node *next;
  long long value;
};

Node *nil;

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

void insertNode(long long value) {
  Node *n = (Node *)malloc(sizeof(Node));
  n->value = value;

  n->next = nil->next;
  nil->next->prev = n;
  nil->next = n;
  n->prev = nil;
}

Node *findNode(long long value) {
  Node *cur = nil->next;
  while (cur != nil) {
    if (cur->value == value)
      return cur;
    cur = cur->next;
  }
  return NULL;
}

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

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

void printList() {
  Node *cur = nil->next;
  while (cur != nil) {
    if (cur->prev != nil)
      printf(" ");
    printf("%lld", cur->value);
    cur = cur->next;
  }
  printf("\\n");
}

int main() {
  int N;
  scanf("%d", &N);

  init();

  for (int i = 0; i < N; ++i) {
    char c[100];
    long long value;
    scanf("%s", c);
    std::string str = c;
    if (str == "insert") {
      scanf("%lld", &value);
      insertNode(value);
    } else if (str == "delete") {
      scanf("%lld", &value);
      deleteNode(findNode(value));
    } else if (str == "deleteFirst") {
      deleteFirst();
    } else if (str == "deleteLast") {
      deleteLast();
    }
  }

  printList();

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

struct Node {
  Node *prev;
  Node *next;
  int value;
};

Node *nil;

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

void insertNode(int value) {
  Node *n = (Node *)malloc(sizeof(Node));
  n->value = value;

  n->next = nil->next;
  nil->next->prev = n;
  nil->next = n;
  n->prev = nil;
}

Node *findNode(int value) {
  Node *cur = nil->next;
  while (cur != nil) {
    if (cur->value == value)
      return cur;
    cur = cur->next;
  }
  return NULL;
}

void deleteNode(Node *n) {
  n->next->prev = n->prev;
  n->prev->next = n->next;
  free(n);
  n = NULL;
}

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

void printList() {
  Node *cur = nil->next;
  while (cur != nil) {
    if (cur->prev != nil)
      printf(" ");
    printf("%d", cur->value);
    cur = cur->next;
  }
  printf("\\n");
}

int main() {
  int N;
  scanf("%d", &N);

  init();

  for (int i = 0; i < N; ++i) {
    char c[100];
    int value;
    scanf("%s", c);
    std::string str = c;
    if (str == "insert") {
      scanf("%d", &value);
      insertNode(value);
    } else if (str == "delete") {
      scanf("%d", &value);
      deleteNode(findNode(value));
    } else if (str == "deleteFirst") {
      deleteFirst();
    } else if (str == "deleteLast") {
      deleteLast();
    }
  }

  printList();

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

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

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

  ll N;
  cin >> N;
  deque<ll> q;
  REP(i, 0, N) {
    string C;
    ll X;
    cin >> C;
    if (C == "insert" || C == "delete")
      cin >> X;

    if (C == "insert") {
      q.push_front(X);
    }
    if (C == "delete") {
      deque<ll> _q;
      bool f = false;
      while (q.size()) {
        if (q.front() != X || f) {
          _q.push_back(q.front());
        } else if (!f) {
          f = true;
        }
        q.pop_front();
      }
      swap(q, _q);
    }
    if (C == "deleteFirst") {
      q.pop_front();
    }
    if (C == "deleteLast") {
      q.pop_back();
    }
  }

  while (q.size()) {
    cout << q.front() << (q.size() != 1 ? " " : "\\n");
    q.pop_front();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll N;
  cin >> N;
  deque<ll> q;
  REP(i, 0, N) {
    string C;
    ll X;
    cin >> C;
    if (C == "insert" || C == "delete")
      cin >> X;

    if (C == "insert") {
      q.push_front(X);
    }
    if (C == "delete") {
      deque<ll> _q;
      bool f = false;
      while (q.size()) {
        if (q.front() != X || f) {
          _q.push_back(q.front());
        } else if (!f) {
          f = true;
        }
        q.pop_front();
      }
      swap(q, _q);
    }
    if (C == "deleteFirst") {
      q.pop_front();
    }
    if (C == "deleteLast") {
      q.pop_back();
    }
  }

  while (q.size()) {
    cout << q.front() << (q.size() != 1 ? " " : "\\n");
    q.pop_front();
  }
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <vector>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

int main() {

  int n;
  cin >> n;

  list<int> lst;
  std::list<int>::iterator itr;

  for (int i = 0; i < n; i++) {
    char str[20];
    cin >> str;
    if (str[0] == 'i') {
      int num;
      cin >> num;
      lst.push_front(num);
    } else if (str[6] == 'F') {
      lst.pop_front();
    } else if (str[6] == 'L') {
      lst.pop_back();
    } else {
      int num;
      cin >> num;
      for (itr = lst.begin(); itr != lst.end();) {
        if (*itr == num) {
          itr = lst.erase(itr);
          break;
        } else {
          itr++;
        }
      }
    }
  }

  itr = lst.begin();

  if (lst.begin() != lst.end()) {
    cout << *itr;
    itr++;
  }

  for (; itr != lst.end(); itr++) {
    cout << " " << *itr;
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <vector>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

int main() {

  int n;
  cin >> n;

  list<int> lst;
  std::list<int>::iterator itr;

  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    if (str == "insert") {
      int num;
      cin >> num;
      lst.push_front(num);
    } else if (str == "delete") {
      int num;
      cin >> num;
      for (itr = lst.begin(); itr != lst.end();) {
        if (*itr == num) {
          itr = lst.erase(itr);
          break;
        } else {
          itr++;
        }
      }
    } else if (str == "deleteFirst") {
      lst.pop_front();
    } else if (str == "deleteLast") {
      lst.pop_back();
    }
  }

  itr = lst.begin();

  if (lst.begin() != lst.end()) {
    cout << *itr;
    itr++;
  }

  for (; itr != lst.end(); itr++) {
    cout << " " << *itr;
  }
  cout << endl;

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

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

int main() {
  list<int> ls;
  char c[21];
  int n;
  cin >> n;
  while (n--) {
    scanf("%s", c);
    if (c[0] == 'i') {
      int t;
      scanf("%d", &t);
      ls.push_front(t);
    } else if (c[6] == 'F')
      ls.pop_front();
    else if (c[6] == 'L')
      ls.pop_back();
    else {
      int t;
      scanf("%d", &t);
      auto ite = find(ls.begin(), ls.end(), t);
      if (ite != ls.end())
        ls.erase(ite);
    }
  }
  int cnt = 0;
  for (auto ite : ls) {
    if (cnt)
      cout << ' ';
    cout << ite;
    cnt++;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  list<int> ls;
  int n;
  cin >> n;
  while (n--) {
    string c;
    int t;
    cin >> c;
    if (c == "insert") {
      int t;
      cin >> t;
      ls.push_front(t);
    } else if (c[6] == 'F')
      ls.pop_front();
    else if (c[6] == 'L')
      ls.pop_back();
    else {
      int t;
      cin >> t;
      auto ite = find(ls.begin(), ls.end(), t);
      if (ite != ls.end())
        ls.erase(ite);
    }
  }
  int c = 0;
  for (auto ite : ls) {
    if (c)
      cout << ' ';
    cout << ite;
    c++;
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int list[2000000];
int head = 999999, tail = 999999;

void Insert(int x) {
  head--;
  list[head] = x;
}

void Delete(int x) {
  for (int i = head; i < tail; ++i)
    if (list[i] == x) {
      for (int j = i; j < tail - 1; ++j)
        list[j] = list[j + 1];
      tail--;
      break;
    }
}

void DeleteFirst() { head++; }

void DeleteLast() { tail--; }

int main() {
  int n;
  scanf("%d", &n);

  char c[12];
  int num;
  for (int i = 0; i < n; ++i) {
    scanf("%s", c);
    if (!strcmp(c, "insert")) {
      scanf("%d", &num);
      Insert(num);
    } else if (!strcmp(c, "delete")) {
      scanf("%d", &num);
      Delete(num);
    } else if (!strcmp(c, "deleteFirst"))
      DeleteFirst();
    else if (!strcmp(c, "deleteLast"))
      DeleteLast();
  }

  for (int i = head; i < tail; i++) {
    if (head < i)
      putchar(' ');
    printf("%d", list[i]);
  }
  putchar('\\n');
}

Error: TLE

Fixed submission:

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

int list[1000000];
int tail = 0;

void Insert(int x) {
  tail++;
  for (int i = tail; 0 < i; --i)
    list[i] = list[i - 1];
  list[0] = x;
}

void Delete(int x) {
  for (int i = 0; i < tail; ++i)
    if (list[i] == x) {
      for (int j = i; j < tail - 1; ++j)
        list[j] = list[j + 1];
      tail--;
      break;
    }
}

void DeleteFirst() {
  for (int i = 0; i < tail - 1; ++i)
    list[i] = list[i + 1];
  tail--;
}

void DeleteLast() { tail--; }

int main() {
  int n;
  scanf("%d", &n);

  char c[12];
  int num;
  for (int i = 0; i < n; ++i) {
    scanf("%s", c);
    if (!strcmp(c, "insert")) {
      scanf("%d", &num);
      Insert(num);
    } else if (!strcmp(c, "delete")) {
      scanf("%d", &num);
      Delete(num);
    } else if (!strcmp(c, "deleteFirst"))
      DeleteFirst();
    else if (!strcmp(c, "deleteLast"))
      DeleteLast();
  }

  for (int i = 0; i < tail; i++) {
    if (0 < i)
      putchar(' ');
    printf("%d", list[i]);
  }
  putchar('\\n');
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <utility>

using namespace std;

void print_list(const list<int> &dlist) {
  const list<int>::const_iterator itEnd = dlist.end();
  for (list<int>::const_iterator it = dlist.begin(); it != itEnd; ++it) {
    if (it != dlist.begin())
      cout << " ";
    cout << *it;
  }
  cout << endl;
}

// void delete_list(list<int> &dlist,int key){
//  list<int>::iterator find_ptr = find_list(dlist,key);

//}

int main() {

  int n = 0;
  cin >> n;

  string command;
  int num;

  list<int> dlist;
  list<int>::iterator it;
  list<int>::iterator l;

  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command == "insert") {
      cin >> num;
      dlist.push_front(num);
    } else if (command == "delete") {
      cin >> num;
      // delete_list(dlist);
      // list<int>::iterator find_ptr = find(dlist.begin(),dlist.end(),num);
      // if()
      for (it = dlist.begin(), l = dlist.end(); it != l; ++it) {
        if (*it == num) {
          dlist.erase(it);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      dlist.pop_front();
    } else {
      dlist.pop_back();
    }
  }

  print_list(dlist);

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <utility>

using namespace std;

void print_list(const list<int> &dlist) {
  const list<int>::const_iterator itEnd = dlist.end();
  for (list<int>::const_iterator it = dlist.begin(); it != itEnd; ++it) {
    if (it != dlist.begin())
      cout << " ";
    cout << *it;
  }
  cout << endl;
}

// void delete_list(list<int> &dlist,int key){
//  list<int>::iterator find_ptr = find_list(dlist,key);

//}

int main() {

  int n = 0;
  cin >> n;

  string command;
  int num;

  list<int> dlist;

  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command == "insert") {
      cin >> num;
      dlist.push_front(num);
    } else if (command == "delete") {
      cin >> num;
      // delete_list(dlist);
      list<int>::iterator find_ptr = find(dlist.begin(), dlist.end(), num);

      dlist.erase(find_ptr);
    } else if (command == "deleteFirst") {
      dlist.pop_front();
    } else {
      dlist.pop_back();
    }
  }

  print_list(dlist);

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <vector>

int main() {
  int n;
  std::scanf("%d", &n);

  std::list<int> l;
  for (int i = 0; i < n; ++i) {
    char command[20];
    std::scanf("%s", command);

    if (std::strcmp(command, "insert") == 0) {
      int a;
      std::scanf("%d", &a);
      l.push_front(a);
    } else if (std::strcmp(command, "delete") == 0) {
      int a;
      std::scanf("%d", &a);
      std::list<int>::iterator it = l.begin();
      while (it != l.end()) {
        if (*it == a) {
          break;
        }
        it++;
      }

      if (it != l.end()) {
        l.erase(it);
      }

    } else if (std::strcmp(command, "deleteFirst") == 0) {
      l.pop_front();
    } else if (std::strcmp(command, "deleteLast") == 0) {
      l.pop_back();
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <vector>

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

  std::list<int> l;
  for (int i = 0; i < n; ++i) {
    std::string command;
    std::cin >> command;

    if (command == "insert") {
      int a;
      std::cin >> a;
      l.push_front(a);
    } else if (command == "delete") {
      int a;
      std::cin >> a;
      std::list<int>::iterator it = l.begin();
      while (it != l.end()) {
        if (*it == a) {
          break;
        }
        it++;
      }

      if (it != l.end()) {
        l.erase(it);
      }

    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
  }

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

  return 0;
}