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

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

int main() {
  int n, x;
  string cmd;
  list<int> alist;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> x;
      alist.push_front(x);
    } else if (cmd == "delete") {
      cin >> x;
      list<int>::iterator ait = alist.begin();
      while (ait != alist.end()) {
        if (*ait == x) {
          alist.erase(ait);
          break;
        } else
          ait++;
      }
    } else if (cmd == "deleteFirst")
      alist.pop_front();
    else
      alist.pop_back();
  }
  n = alist.size();
  list<int>::iterator ait = alist.begin();
  for (int i = 0; i < n - 1; i++)
    cout << *ait++ << ' ';
  cout << *ait << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, x;
  string cmd;
  list<int> alist;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> x;
      alist.push_front(x);
    } else if (cmd == "delete") {
      cin >> x;
      list<int>::iterator ait = alist.begin();
      while (1) {
        if (*ait == x) {
          alist.erase(ait);
          break;
        } else
          ait++;
      }
    } else if (cmd == "deleteFirst")
      alist.pop_front();
    else
      alist.pop_back();
  }
  n = alist.size();
  list<int>::iterator ait = alist.begin();
  for (int i = 0; i < n - 1; i++)
    cout << *ait++ << ' ';
  cout << *ait << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <stdlib.h>
using namespace std;

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

node *nil;

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

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;
}

node *search(int key) {
  node *cur;
  for (cur = nil->next; cur != nil; cur = cur->next)
    if (cur->key == key)
      return cur;
  return cur;
}

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

void delFL(int n) {
  if (n)
    delnode(nil->next);
  else
    delnode(nil->prev);
}

int main() {
  int n, key;
  cin >> n;
  char str[1000];
  init();
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    if (str[6] == 'F')
      delFL(1);
    else if (str[6] == 'L')
      delFL(0);
    else {
      scanf("%d", &key);
      if (str[0] == 'i')
        insert(key);
      else if (str[0] == 'd')
        delnode(search(key));
    }
  }

  node *cur;
  for (cur = nil->next; cur->next != nil; cur = cur->next)
    cout << cur->key << " ";
  cout << cur->key << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdlib.h>
using namespace std;

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

node *nil;

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

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;
}

node *search(int key) {
  node *cur;
  for (cur = nil->next; cur != nil; cur = cur->next)
    if (cur->key == key)
      return cur;
  return cur;
}

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

void delFL(int n) {
  if (n)
    delnode(nil->next);
  else
    delnode(nil->prev);
}

int main() {
  int n, key;
  cin >> n;
  string str;
  init();
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "deleteFirst")
      delFL(1);
    else if (str == "deleteLast")
      delFL(0);
    else {
      cin >> key;
      if (str == "insert")
        insert(key);
      else if (str == "delete")
        delnode(search(key));
    }
  }

  node *cur;
  for (cur = nil->next; cur->next != nil; cur = cur->next)
    cout << cur->key << " ";
  cout << cur->key << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

class c_doubly {
private:
public:
  c_doubly();
  void f_input();
};

c_doubly::c_doubly() {}

void c_doubly::f_input() {
  int n;
  int n_key;
  int i;
  string s;
  list<int> d_doubly;

  cin >> n;

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

  /*
  i = 1;
  list<int>::iterator it = d_doubly.begin();
  while( it != d_doubly.end() )
  {
      if (i != d_doubly.size()){
          cout << *it << " ";
          ++i;
      }else{
          cout << *it << endl;
      }
      ++it;
  }
  */
  n = d_doubly.size();
  list<int>::iterator it = d_doubly.begin();
  // cout << "n: " << n << endl;
  for (i = 0; i < n; ++i) {
    if (i == n - 1) {
      cout << *it << endl;
    } else {
      cout << *it << " ";
    }
    ++it;
  }
}

int main() {

  c_doubly doubly01;
  doubly01.f_input();

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

class c_doubly {
private:
public:
  c_doubly();
  void f_input();
};

c_doubly::c_doubly() {}

void c_doubly::f_input() {
  int n;
  int n_key;
  int i;
  string s;
  list<int> d_doubly;

  cin >> n;

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

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

int main() {

  c_doubly doubly01;
  doubly01.f_input();

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

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

int a[5000000];
int first = 0, last = 0;
int n, m, q;
string w;

void insert() {
  a[last] = n;
  last++;
}

void deleteFirst() { last--; }

void deleteLast() { first++; }

void _delete() {
  for (int k = last - 1; k >= first; k--) {
    if (a[k] == n) {
      m = k;
      for (int k = m; k < last - 1; k++) {
        a[k] = a[k + 1];
      }
      last--;
      break;
    }
  }
}

void owata() {
  for (int k = last - 1; k >= first; k--) {
    cout << a[k];
    if (k == first) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}

void hantei() {
  if (w == "insert") {
    cin >> n;
    insert();
  }
  if (w == "delete") {
    cin >> n;
    _delete();
  }
  if (w == "deleteFirst") {
    deleteFirst();
  }
  if (w == "deleteLast") {
    deleteLast();
  }
}

int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> w;
    hantei();
  }
  owata();
  return 0;
}

Error: TLE

Fixed submission:

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

int a[5000000];
int first = 0, last = 0;
int n, m, q;
string w;

void insert() {
  a[last] = n;
  last++;
}

void deleteFirst() { last--; }

void deleteLast() { first++; }

void _delete() {
  for (int k = last - 1; k >= first; k--) {
    if (a[k] == n) {
      m = k;
      for (int k = m; k < last - 1; k++) {
        a[k] = a[k + 1];
      }
      last--;
      goto Exit1;
    }
  }
Exit1:;
}

void owata() {
  for (int k = last - 1; k >= first; k--) {
    cout << a[k];
    if (k == first) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}

void hantei() {
  if (w == "insert") {
    cin >> n;
    insert();
  }
  if (w == "delete") {
    cin >> n;
    _delete();
  }
  if (w == "deleteFirst") {
    deleteFirst();
  }
  if (w == "deleteLast") {
    deleteLast();
  }
}

int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> w;
    hantei();
  }
  owata();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

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

  deque<int> deq;
  int N;
  cin >> N;

  while (N--) {
    string cmd;
    cin >> cmd;
    if (cmd == "insert") {
      int x;
      cin >> x;
      deq.push_front(x);
    } else if (cmd == "delete") {
      int x;
      cin >> x;
      auto it = find(deq.begin(), deq.end(), x);
      if (it != deq.end())
        deq.erase(it);
    }
    if (cmd == "deleteFirst")
      deq.pop_front();
    if (cmd == "deleteLast")
      deq.pop_back();
  }

  if (!deq.empty()) {
    cout << deq.front();
    for (auto it = deq.begin() + 1; it != deq.end(); ++it)
      cout << " " << *it;
    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

int main() {
  deque<int> deq;
  int N;
  cin >> N;

  while (N--) {
    string cmd;
    cin >> cmd;
    if (cmd == "insert") {
      int x;
      cin >> x;
      deq.push_front(x);
    } else if (cmd == "delete") {
      int x;
      cin >> x;
      auto it = find(deq.begin(), deq.end(), x);
      if (it != deq.end())
        deq.erase(it);
    }
    if (cmd == "deleteFirst")
      deq.pop_front();
    if (cmd == "deleteLast")
      deq.pop_back();
  }

  if (!deq.empty()) {
    cout << deq.front();
    for (auto it = deq.begin() + 1; it != deq.end(); ++it)
      cout << " " << *it;
    cout << endl;
  }

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

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

class TDllist {
  std::list<int> FList;

public:
  void Insert(int X) { FList.push_front(X); }
  void Delete(int X) {
    for (std::list<int>::iterator It = FList.begin(); It != FList.end(); ++It) {
      if (*It == X) {
        FList.erase(It);
        return;
      }
    }
  }
  void DeleteFirst() { FList.pop_front(); }
  void DeleteLast() { FList.pop_back(); }
  void Show() const {
    std::list<int>::const_iterator It = FList.begin();
    std::cout << *It;
    for (++It; It != FList.end(); ++It) {
      std::cout << " " << *It;
    }
    std::cout << std::endl;
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  TDllist List;
  int n, X;
  std::cin >> n;
  std::string Command;
  for (int i = 0; i < n; ++i) {
    // std::string Command;
    std::cin >> Command;
    if (Command == "insert") {
      // int X;
      std::cin >> X;
      List.Insert(X);
    } else if (Command == "delete") {
      // int X;
      std::cin >> X;
      List.Delete(X);
    } else if (Command == "deleteFirst") {
      List.DeleteFirst();
    } else if (Command == "deleteLast") {
      List.DeleteLast();
    } else {
      assert(false);
    }
  }
  List.Show();
  return 0;
}

Error: TLE

Fixed submission:

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

class TDllist {
  std::list<int> FList;

public:
  void Insert(int X) { FList.push_front(X); }
  void Delete(int X) {
    for (std::list<int>::iterator It = FList.begin(); It != FList.end(); ++It) {
      if (*It == X) {
        FList.erase(It);
        return;
      }
    }
  }
  void DeleteFirst() { FList.pop_front(); }
  void DeleteLast() { FList.pop_back(); }
  void Show() const {
    std::list<int>::const_iterator It = FList.begin();
    std::cout << *It;
    for (++It; It != FList.end(); ++It) {
      std::cout << " " << *It;
    }
    std::cout << std::endl;
  }
};

int main() {
  std::cin.tie(0);
  TDllist List;
  int n, X;
  std::cin >> n;
  std::string Command;
  for (int i = 0; i < n; ++i) {
    // std::string Command;
    std::cin >> Command;
    if (Command == "insert") {
      // int X;
      std::cin >> X;
      List.Insert(X);
    } else if (Command == "delete") {
      // int X;
      std::cin >> X;
      List.Delete(X);
    } else if (Command == "deleteFirst") {
      List.DeleteFirst();
    } else if (Command == "deleteLast") {
      List.DeleteLast();
    } else {
      assert(false);
    }
  }
  List.Show();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>
#include <iostream>
#include <list>
#include <string>
// #include <vector>

class TDllist {
  std::list<int> FList;
  // std::vector<int> FList;
public:
  void Insert(int X) {
    FList.push_front(X);
    // FList.insert(FList.begin(), X);
  }
  void Delete(int X) {
    for (auto It = FList.begin(); It != FList.end(); ++It) {
      if (*It == X) {
        FList.erase(It);
        return;
      }
    }
  }
  void DeleteFirst() {
    FList.pop_front();
    // FList.erase(FList.begin());
  }
  void DeleteLast() { FList.pop_back(); }
  void Show() const {
    auto It = FList.begin();
    std::cout << *It;
    for (++It; It != FList.end(); ++It) {
      std::cout << " " << *It;
    }
    std::cout << std::endl;
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  TDllist List;
  int n, X;
  std::cin >> n;
  std::string Command;
  for (int i = 0; i < n; ++i) {
    // std::string Command;
    std::cin >> Command;
    if (Command == "insert") {
      // int X;
      std::cin >> X;
      List.Insert(X);
    } else if (Command == "delete") {
      // int X;
      std::cin >> X;
      List.Delete(X);
    } else if (Command == "deleteFirst") {
      List.DeleteFirst();
    } else if (Command == "deleteLast") {
      List.DeleteLast();
    } else {
      assert(false);
    }
  }
  List.Show();
  return 0;
}

Error: TLE

Fixed submission:

#include <cassert>
#include <iostream>
#include <list>
#include <string>
#include <vector>

class TDllist {
  // std::list<int> FList;
  std::vector<int> FList;

public:
  void Insert(int X) {
    // FList.push_front(X);
    FList.insert(FList.begin(), X);
  }
  void Delete(int X) {
    for (auto It = FList.begin(); It != FList.end(); ++It) {
      if (*It == X) {
        FList.erase(It);
        return;
      }
    }
  }
  void DeleteFirst() {
    // FList.pop_front();
    FList.erase(FList.begin());
  }
  void DeleteLast() { FList.pop_back(); }
  void Show() const {
    auto It = FList.begin();
    std::cout << *It;
    for (++It; It != FList.end(); ++It) {
      std::cout << " " << *It;
    }
    std::cout << std::endl;
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  TDllist List;
  int n, X;
  std::cin >> n;
  std::string Command;
  for (int i = 0; i < n; ++i) {
    // std::string Command;
    std::cin >> Command;
    if (Command == "insert") {
      // int X;
      std::cin >> X;
      List.Insert(X);
    } else if (Command == "delete") {
      // int X;
      std::cin >> X;
      List.Delete(X);
    } else if (Command == "deleteFirst") {
      List.DeleteFirst();
    } else if (Command == "deleteLast") {
      List.DeleteLast();
    } else {
      assert(false);
    }
  }
  List.Show();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
int main() {
  ios::sync_with_stdio(false);
  list<int> lis;
  int cnt;
  cin >> cnt;
  string tmp;
  int tmpI;
  for (int i = 0; i < cnt; i++) {
    cin >> tmp;
    if (tmp[0] == 'i') { // insert x
      cin >> tmpI;
      lis.push_front(tmpI);
    } else if (tmp == "delete") { // delete x
      cin >> tmpI;
      for (list<int>::iterator it = lis.begin(); it != lis.end(); it++) {
        if (*it == tmpI) {
          lis.erase(it);
          break;
        }
      }
    } else if (tmp[6] == 'F') { // deleteF
      lis.pop_front();
    } else { // deleteL
      lis.pop_back();
    }
  }
  for (list<int>::iterator it = lis.begin(); it != lis.end(); it++) {
    if (it != lis.begin()) {
      cout << " ";
    }
    cout << *it;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int main() {
  ios::sync_with_stdio(false);
  list<int> lis;
  int cnt;
  cin >> cnt;
  string tmp;
  int tmpI;
  for (int i = 0; i < cnt; i++) {
    cin >> tmp;
    if (tmp[0] == 'i') { // insert x
      cin >> tmpI;
      lis.push_front(tmpI);
    } else if (tmp == "delete") { // delete x
      cin >> tmpI;
      for (list<int>::iterator it = lis.begin(); it != lis.end(); i++) {
        if (*it == tmpI) {
          lis.erase(it);
          break;
        }
      }
    } else if (tmp[6] == 'F') { // deleteF
      lis.pop_front();
    } else { // deleteL
      lis.pop_back();
    }
  }
  for (list<int>::iterator it = lis.begin(); it != lis.end(); it++) {
    if (it != lis.begin()) {
      cout << " ";
    }
    cout << *it;
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

class ele {
public:
  ele();
  int key;
  ele *prev, *next;
};

ele::ele() {}

ele *null = new ele();

void insert(int n) {
  ele *node = new ele();
  node->key = n;
  node->prev = null;
  node->next = null->next;
  null->next->prev = node;
  null->next = node;
}

ele *search(int n) {
  ele *ser = new ele();
  ser = null->next;
  while (ser != null && ser->key != n) {
    ser = ser->next;
  }
  return ser;
}

void adelete(ele *a) {
  if (a == null)
    return;
  a->prev->next = a->next;
  a->next->prev = a->prev;
  delete a;
}

void searchdelete(int n) { adelete(search(n)); }

void deletefirst() { adelete(null->next); }

void deletelast() { adelete(null->prev); }

int main() {
  null->prev = null->next = null;
  int n, i, a;
  char c[11];
  string str;
  ele *e = new ele();
  e = null;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", c);
    str = c;
    if (str == "deleteLast")
      deletelast();
    else if (str == "deleteFirst")
      deletefirst();
    else if (str == "insert") {
      scanf("%d", &a);
      insert(a);
    } else {
      scanf("%d", &a);
      searchdelete(a);
    }
  }
  e = e->next;
  while (e != null->prev) {
    printf("%d ", e->key);
    e = e->next;
  }
  printf("%d\\n", e->key);
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

class ele {
public:
  ele();
  int key;
  ele *prev, *next;
};

ele::ele() {}

ele *null = new ele();

void insert(int n) {
  ele *node = new ele();
  node->key = n;
  node->prev = null;
  node->next = null->next;
  null->next->prev = node;
  null->next = node;
}

ele *search(int n) {
  ele *ser = new ele();
  ser = null->next;
  while (ser != null && ser->key != n) {
    ser = ser->next;
  }
  return ser;
}

void adelete(ele *a) {
  if (a == null)
    return;
  a->prev->next = a->next;
  a->next->prev = a->prev;
  delete a;
}

void searchdelete(int n) { adelete(search(n)); }

void deletefirst() { adelete(null->next); }

void deletelast() { adelete(null->prev); }

int main() {
  null->prev = null->next = null;
  int n, i, a;
  string str;
  ele *e = new ele();
  e = null;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    cin >> str;
    if (str == "deleteLast")
      deletelast();
    else if (str == "deleteFirst")
      deletefirst();
    else if (str == "insert") {
      scanf("%d", &a);
      insert(a);
    } else {
      scanf("%d", &a);
      searchdelete(a);
    }
  }
  e = e->next;
  while (e != null->prev) {
    printf("%d ", e->key);
    e = e->next;
  }
  printf("%d\\n", e->key);
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <list>
#include <string>
using namespace std;

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

  list<int> l;
  while (n--) {
    char cmdChar[64];
    scanf("%s", cmdChar);
    string command(cmdChar);
    if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    } else {
      int i;
      scanf("%d", &i);
      if (command == "insert") {
        l.push_front(i);
      } else if (command == "delete") {
        list<int>::iterator it = l.begin();
        while (it != l.end()) {
          if (i == *it) {
            l.erase(it);
            break;
          }
          it++;
        }
      }
    }
  }
  list<int>::iterator it = l.begin();
  while (it != l.end()) {
    printf("%d", *it);
    it++;
    printf("%c", it == l.end() ? '\\n' : ' ');
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

  list<int> l;
  while (n--) {
    string command;
    cin >> command;
    if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    } else {
      int i;
      cin >> i;
      if (command == "insert") {
        l.push_front(i);
      } else if (command == "delete") {
        list<int>::iterator it = l.begin();
        while (it != l.end()) {
          if (i == *it) {
            l.erase(it);
            break;
          }
          it++;
        }
      }
    }
  }
  list<int>::iterator it = l.begin();
  while (it != l.end()) {
    cout << *it;
    it++;
    cout << (it == l.end() ? "" : " ");
  }
  cout << endl;

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

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

int main() {
  std::ios::sync_with_stdio(false);
  list<unsigned long long> dat(0);
  list<unsigned long long>::iterator t = dat.begin();
  string com;
  int n, a;

  cin >> n;

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

    if (com == "insert") {
      cin >> a;
      dat.push_front(a);
    } else if (com == "delete") {
      cin >> a;
      t = dat.begin();
      while (t != dat.end() && *t != (unsigned long long)a) {
        t++;
      }
      if (*t == (unsigned long long)a)
        dat.erase(t);
    } else if (com == "deleteFirst") {
      dat.pop_front();
    } else {
      dat.pop_back();
    }
  }

  t = dat.begin();
  printf("%Ld", *t++);
  while (t != dat.end()) {
    printf(" %Ld", *t++);
  }
  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  list<unsigned int> dat(0);
  string com;
  int n, a;

  cin >> n;

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

    if (com == "insert") {
      cin >> a;
      dat.push_front(a);
    } else if (com == "delete") {
      cin >> a;
      list<unsigned int>::iterator t = dat.begin();
      while (t != dat.end() && *t != (unsigned int)a) {
        t++;
      }
      if (*t == (unsigned int)a)
        dat.erase(t);
    } else if (com == "deleteFirst") {
      dat.pop_front();
    } else {
      dat.pop_back();
    }
  }

  list<unsigned int>::iterator t = dat.begin();
  printf("%d", *t++);
  while (t != dat.end()) {
    printf(" %d", *t++);
  }
  printf("\\n");

  return 0;
}