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

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

deque<long long int> dq;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, i;
  cin >> n;
  string s;
  int value;
  deque<long long int>::iterator it = dq.begin();
  for (i = 0; i < n; ++i) {
    cin >> s;
    if (s == "insert") {
      cin >> value;
      dq.push_front(value);
    } else if (s == "delete") {
      cin >> value;
      deque<long long int>::iterator itr = dq.begin();
      while (itr != dq.end()) {
        if (*itr == value) {
          dq.erase(itr);
          break;
        }
        itr++;
      }
    } else if (s == "deleteFirst") {
      dq.pop_front();
    } else if (s == "deleteLast") {
      dq.pop_back();
    }
  }
  int cnt = 0;

  for (it = dq.begin(); it != dq.end(); ++it) {
    cnt++;
  }
  for (i = 0; i < cnt - 1; ++i) {
    cout << dq[i] << " ";
  }
  cout << dq[i];
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

Node *root = new Node;

void insert_key(int x) {
  if (root->next == NULL) {
    root->value = x;
    Node *tmp = new Node;
    root->next = tmp;
    tmp->prev = root;
    tmp->next = NULL;
    tmp->value = 0;
  } else {
    Node *tmp = new Node;
    tmp->prev = NULL;
    tmp->next = root;
    tmp->value = x;
    root->prev = tmp;
    root = tmp;
  }
}
void delete_key(int x) {
  for (Node *tmp = root; tmp->next != NULL; tmp = tmp->next) {
    if (tmp->value == x) {
      Node *tmp2 = tmp->prev;
      if (tmp->prev != NULL) {
        tmp2->next = tmp->next;
        Node *tmp3 = tmp->next;
        tmp3->prev = tmp2;
        delete tmp;
      } else {
        root = tmp->next;
        root->prev = NULL;
        delete tmp;
      }
      break;
    }
  }
}
void delete_first() {
  Node *tmp = root;
  root = root->next;
  root->prev = NULL;
  delete tmp;
}

void delete_last() {
  Node *tmp = root;
  while (tmp->next != NULL)
    tmp = tmp->next;
  Node *tmp2 = tmp->prev;
  tmp2->next = NULL;
  delete tmp;
}

int main() {
  int n, i;
  cin >> n;
  string s;
  int x;
  root->prev = NULL;
  root->next = NULL;
  root->value = 0;
  for (i = 0; i < n; ++i) {
    cin >> s;
    cin.ignore();
    if (s == "insert") {
      cin >> x;
      insert_key(x);
    } else if (s == "delete") {
      cin >> x;
      delete_key(x);
    } else if (s == "deleteFirst") {
      delete_first();
    } else if (s == "deleteLast") {
      delete_last();
    }
  }

  int cnt = 0;
  for (Node *tmp = root; tmp->next != NULL; tmp = tmp->next) {
    cnt++;
  }
  Node *tmp = root;
  for (int i = 0; i < cnt - 1; ++i) {
    cout << tmp->value << " ";
    Node *tmp2 = tmp;
    tmp = tmp->next;
    delete tmp2;
  }
  cout << tmp->value;
  cout << endl;
  delete tmp;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

deque<long long int> dq;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, i;
  cin >> n;
  string s;
  int value;
  deque<long long int>::iterator it = dq.begin();
  for (i = 0; i < n; ++i) {
    cin >> s;
    if (s == "insert") {
      cin >> value;
      dq.push_front(value);
    } else if (s == "delete") {
      cin >> value;
      deque<long long int>::iterator itr = dq.begin();
      while (itr != dq.end()) {
        if (*itr == value) {
          dq.erase(itr);
          break;
        }
        itr++;
      }
    } else if (s == "deleteFirst") {
      dq.pop_front();
    } else if (s == "deleteLast") {
      dq.pop_back();
    }
  }
  int cnt = 0;

  for (it = dq.begin(); it != dq.end(); ++it) {
    cnt++;
  }
  for (i = 0; i < cnt - 1; ++i) {
    cout << dq[i] << " ";
  }
  cout << dq[i];
  cout << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

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

Node *root = new Node;

void insert_key(int x) {
  if (root->next == NULL) {
    root->value = x;
    Node *tmp = new Node;
    root->next = tmp;
    tmp->prev = root;
    tmp->next = NULL;
    tmp->value = 0;
  } else {
    Node *tmp = new Node;
    tmp->prev = NULL;
    tmp->next = root;
    tmp->value = x;
    root->prev = tmp;
    root = tmp;
  }
}
void delete_key(int x) {
  for (Node *tmp = root; tmp->next != NULL; tmp = tmp->next) {
    if (tmp->value == x) {
      Node *tmp2 = tmp->prev;
      if (tmp->prev != NULL) {
        tmp2->next = tmp->next;
        Node *tmp3 = tmp->next;
        tmp3->prev = tmp2;
        delete tmp;
      } else {
        root = tmp->next;
        root->prev = NULL;
        delete tmp;
      }
      break;
    }
  }
}
void delete_first() {
  Node *tmp = root;
  root = root->next;
  root->prev = NULL;
  delete tmp;
}

void delete_last() {
  Node *tmp = root;
  while (tmp->next != NULL)
    tmp = tmp->next;
  Node *tmp2 = tmp->prev;
  tmp2->next = NULL;
  delete tmp;
}

int main() {
  int n, i;
  cin >> n;
  vector<string> v(n);
  int *x = new int[n];
  root->prev = NULL;
  root->next = NULL;
  root->value = 0;
  for (i = 0; i < n; ++i) {
    cin >> v[i];
    if (v[i] == "insert") {
      cin >> x[i];
      insert_key(x[i]);
    } else if (v[i] == "delete") {
      cin >> x[i];
      delete_key(x[i]);
    } else if (v[i] == "deleteFirst") {
      delete_first();
    } else if (v[i] == "deleteLast") {
      delete_last();
    }
  }

  int cnt = 0;
  for (Node *tmp = root; tmp->next != NULL; tmp = tmp->next) {
    cnt++;
  }
  Node *tmp = root;
  for (int i = 0; i < cnt - 1; ++i) {
    cout << tmp->value << " ";
    Node *tmp2 = tmp;
    tmp = tmp->next;
    delete tmp2;
  }
  cout << tmp->value;
  delete tmp;
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)

deque<int> lst;
int main() {
  int n, v;
  string s;
  cin >> n;
  rep(i, n) {
    cin >> s;
    if (s == "insert") {
      cin >> v;
      lst.push_front(v);
    } else if (s == "delete") {
      cin >> v;
      auto it = find(lst.begin(), lst.end(), v);
      if (it != lst.end())
        lst.erase(it);
    } else if (s == "deleteFirst") {
      lst.pop_front();
    } else if (s == "deleteLast") {
      lst.pop_back();
    }
  }
  for (auto it = lst.begin(); it != --lst.end(); ++it) {
    cout << *it << " ";
  }
  cout << *--lst.end() << endl;
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)

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

/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C
 */
#include <iostream>
#include <list>
#include <string>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  cin.ignore();

  list<int> lst;
  for (int i = 0; i < n; i++) {
    string cmd;
    getline(cin, cmd);

    switch (cmd[6]) {
    case 'F':
      lst.pop_front();
      break;
    case 'L':
      lst.pop_back();
      break;
    default:
      int k = stoi(cmd.substr(7));
      if (cmd[0] == 'i') {
        lst.push_front(k);
      } else {
        for (auto it = lst.cbegin(); it != lst.cend(); it++) {
          if (*it == k) {
            lst.erase(it);
            break;
          }
        }
      }
    }
  }
  for (auto it = lst.begin(); it != lst.end(); it++) {
    if (it != lst.begin()) {
      cout << ' ';
    }
    cout << *it;
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C
 */
#include <iostream>
#include <list>
#include <string>

using namespace std;

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

  list<int> lst;
  for (int i = 0; i < n; i++) {
    string cmd;
    getline(cin, cmd);

    switch (cmd[6]) {
    case 'F':
      lst.pop_front();
      break;
    case 'L':
      lst.pop_back();
      break;
    default:
      int k = 0;
      int len = cmd.length() - 7;
      switch (len) {
      case 10:
        k += (cmd[len - 3] - '0') * 1000000000;
      case 9:
        k += (cmd[len - 2] - '0') * 100000000;
      case 8:
        k += (cmd[len - 1] - '0') * 10000000;
      case 7:
        k += (cmd[len] - '0') * 1000000;
      case 6:
        k += (cmd[len + 1] - '0') * 100000;
      case 5:
        k += (cmd[len + 2] - '0') * 10000;
      case 4:
        k += (cmd[len + 3] - '0') * 1000;
      case 3:
        k += (cmd[len + 4] - '0') * 100;
      case 2:
        k += (cmd[len + 5] - '0') * 10;
      case 1:
        k += (cmd[len + 6] - '0');
      }
      if (cmd[0] == 'i') {
        lst.push_front(k);
      } else {
        for (auto it = lst.cbegin(); it != lst.cend(); it++) {
          if (*it == k) {
            lst.erase(it);
            break;
          }
        }
      }
    }
  }
  for (auto it = lst.begin(); it != lst.end(); it++) {
    if (it != lst.begin()) {
      cout << ' ';
    }
    cout << *it;
  }
  cout << endl;

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

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

int main() {
  list<int> l;
  int commands;
  char command[20];
  int data;
  cin >> commands;

  for (int i = 0; i < commands; i++) {
    cin >> command;
    if (command[0] == 'i') {
      cin >> data;
      l.push_front(data);
    } else if (command[6] == 'F') {
      l.pop_front();
    } else if (command[6] == 'L') {
      l.pop_back();
    } else if (command[0] == 'd') {
      cin >> data;
      for (list<int>::iterator itr = l.begin(); itr != l.end(); ++itr) {
        if (*itr == data) {
          l.erase(itr);
          break;
        }
      }
    }
  }
  list<int>::iterator last = l.end();
  --last;
  for (list<int>::iterator itr = l.begin(); itr != l.end(); ++itr) {
    cout << *itr;
    if (itr != last)
      cout << " ";
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  list<int> l;
  int commands;
  char *command;
  int data;
  cin >> commands;

  for (int i = 0; i < commands; i++) {
    cin >> command >> data;
    if (command == "insert") {
      l.push_front(data);
    } else if (command == "delete") {
      for (list<int>::iterator itr = l.begin(); itr != l.end(); ++itr) {
        if (*itr == data) {
          l.erase(itr);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
  }

  for (list<int>::iterator itr = 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>
#include <iostream>
#include <string>
using namespace std;
class Node {
public:
  int key;
  Node *prev, *next;
};
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 (true) {
    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->prev = nil;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
}
int main() {
  init();
  int n, key;
  char com[20];
  scanf("%d", &n);
  for (int 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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class Node {
public:
  int key;
  Node *prev, *next;
};
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 (true) {
    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->prev = nil;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
}
int main() {
  init();
  int n, key;
  string s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      scanf("%d", &key);
      insert(key);
    } else if (s == "delete") {
      scanf("%d", &key);
      deleteKey(key);
    } else if (s == "deleteFirst") {
      deleteFirst();
    } else if (s == "deleteLast") {
      deleteLast();
    }
  }
  printList();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <string>
int main(void) {
  int n;
  std::cin >> n;
  std::list<int> List;
  std::string CommandInput;
  int KeyInput;
  for (int i = 0; i < n; ++i) {
    std::cin >> CommandInput;
    if (CommandInput == "insert") {
      std::cin >> KeyInput;
      List.push_front(KeyInput);
    } else if (CommandInput == "delete") {
      std::cin >> KeyInput;
      for (std::list<int>::iterator itr = List.begin(); itr != List.end();
           ++itr) {
        if (*itr == KeyInput) {
          itr = List.erase(itr);
          break;
        }
      }
    } else if (CommandInput == "deleteFirst") {
      List.pop_front();
    } else if (CommandInput == "deleteLast") {
      List.pop_back();
    }
  }
  std::list<int>::iterator enditr = List.end();
  enditr--;
  for (std::list<int>::iterator itr = List.begin(); itr != List.end(); ++itr) {
    if (itr != enditr) {
      std::cout << *itr << " ";
    } else {
      std::cout << *itr << std::endl;
    }
  }
  // system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <string>
int main(void) {
  int n;
  std::cin >> n;
  std::list<int> List;
  for (int i = 0; i < n; ++i) {
    std::string CommandInput;
    int KeyInput;
    std::cin >> CommandInput;
    if (CommandInput == "insert") {
      std::cin >> KeyInput;
      List.push_front(KeyInput);
    } else if (CommandInput == "delete") {
      std::cin >> KeyInput;
      for (std::list<int>::iterator itr = List.begin(); itr != List.end();
           ++itr) {
        if (*itr == KeyInput) {
          itr = List.erase(itr);
          break;
        }
      }
    } else if (CommandInput == "deleteFirst") {
      List.pop_front();
    } else if (CommandInput == "deleteLast") {
      List.pop_back();
    }
  }
  std::list<int>::iterator enditr = List.end();
  enditr--;
  for (std::list<int>::iterator itr = List.begin(); itr != List.end(); ++itr) {
    if (itr != enditr) {
      std::cout << *itr << " ";
    } else {
      std::cout << *itr << std::endl;
    }
  }
  // system("pause");
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
struct node {
  node *pre, *next;
  int key;
};

node *head;

node *find(int x) {
  node *ima = head->next;
  while (ima->key != x && ima != head)
    ima = ima->next;
  return ima;
}

void mk_node(int key, node *next, node *prev) {
  node *n = (node *)malloc(sizeof(node));
  n->key = key;
  n->next = next;
  n->pre = prev;
  next->pre = n;
  prev->next = n;
}

void insert(int x) { mk_node(x, head->next, head); }

void del(int x) {
  node *del = find(x);
  if (del->key != x)
    return;
  del->pre->next = del->next;
  del->next->pre = del->pre;
  free(del);
}

void delF() {
  node *del = head->next;
  if (del == head)
    return;
  del->next->pre = head;
  head->next = del->next;
  free(del);
}

void delL() {
  node *del = head->pre;
  if (del == head)
    return;
  del->pre->next = head;
  head->pre = del->pre;
  free(del);
}

char str[1000];

int main() {
  head = (node *)malloc(sizeof(node *));
  head->next = head;
  head->pre = head;
  head->key = -1;

  int n;
  cin >> n;
  while (n--) {

    int a;
    scanf("%s", str);
    if (str[0] == 'i') {
      scanf("%d", &a);
      insert(a);
    }

    if (str[0] == 'd' && strlen(str) == 6) {
      scanf("%d", &a);
      del(a);
    } else {
      if (str[6] == 'F')
        delF();
      if (str[6] == 'L')
        delL();
    }
  }

  node *ima = head->next;
  while (ima->next != head && ima->key != -1)
    cout << ima->key << " ", ima = ima->next;
  cout << ima->key << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
struct node {
  node *pre, *next;
  int key;
};

node *head;

node *find(int x) {
  node *ima = head->next;
  while (ima->key != x && ima != head)
    ima = ima->next;
  return ima;
}

void mk_node(int key, node *next, node *prev) {
  node *n = (node *)malloc(sizeof(node));
  n->key = key;
  n->next = next;
  n->pre = prev;
  next->pre = n;
  prev->next = n;
}

void insert(int x) { mk_node(x, head->next, head); }

void del(int x) {
  node *del = find(x);
  if (del->key != x)
    return;
  del->pre->next = del->next;
  del->next->pre = del->pre;
  free(del);
}

void delF() {
  node *del = head->next;
  if (del == head)
    return;
  del->next->pre = head;
  head->next = del->next;
  free(del);
}

void delL() {
  node *del = head->pre;
  if (del == head)
    return;
  del->pre->next = head;
  head->pre = del->pre;
  free(del);
}

int main() {
  head = (node *)malloc(sizeof(node *));
  head->next = head;
  head->pre = head;
  head->key = -1;

  int n;
  cin >> n;
  while (n--) {
    string str;
    int a;
    cin >> str;
    if (str == "insert") {
      scanf("%d", &a);
      insert(a);
    }
    if (str == "delete") {
      scanf("%d", &a);
      del(a);
    }
    if (str == "deleteFirst")
      delF();
    if (str == "deleteLast")
      delL();
  }

  node *ima = head->next;
  while (ima->next != head && ima->key != -1)
    cout << ima->key << " ", ima = ima->next;
  cout << ima->key << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

class MyList {
private:
  const int MAX_N = 2000000;
  int *lst = new int[MAX_N];
  int first = MAX_N - 1;
  int last = MAX_N - 1;

public:
  MyList();
  void insert(int x);
  void remove(int x);
  void deleteFirst();
  void deleteLast();
  int size();
  void print();
};

MyList::MyList() { REP(i, MAX_N) lst[i] = -1; }

void MyList::insert(int x) {
  lst[first] = x;
  first--;
}

void MyList::deleteLast() { last--; }

void MyList::deleteFirst() { first++; }

int MyList::size() { return last - first; }

void MyList::remove(int x) {
  int xpos = -1;
  for (int i = first + 1; i <= last; i++) {
    if (lst[i] == x) {
      xpos = i;
      break;
    }
  }
  if (xpos == -1)
    return;
  else {
    for (int i = xpos; i > first + 1; i--) {
      lst[i] = lst[i - 1];
    }
    first++;
  }
}

void MyList::print() {
  for (int i = first + 1; i < last; i++) {
    cout << lst[i] << " ";
  }
  cout << lst[last] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  MyList mylist;
  REP(i, n) {
    string s;
    cin >> s;
    if (s == "insert") {
      int k;
      cin >> k;
      mylist.insert(k);
    } else if (s == "deleteFirst") {
      mylist.deleteFirst();
    } else if (s == "deleteLast") {
      mylist.deleteLast();
    } else {
      int k;
      cin >> k;
      mylist.remove(k);
    }
    // mylist.print();
  }
  mylist.print();
  return 0;
}

Error: TLE

Fixed submission:

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

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

class DLL : public list<int> {
public:
  void deletex(int x);
  void print();
};

void DLL::deletex(int x) {
  auto itr = this->begin();
  REP(i, this->size()) {
    if (*(itr) == x) {
      this->erase(itr);
      return;
    }
    itr++;
  }
}

void DLL::print() {
  auto itr = this->begin();
  REP(i, this->size() - 1) {
    cout << *(itr) << " ";
    itr++;
  }
  cout << *(itr) << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  DLL lst;
  REP(i, n) {
    string s;
    cin >> s;
    if (s == "insert") {
      int k;
      cin >> k;
      lst.push_front(k);
    } else if (s == "delete") {
      int k;
      cin >> k;
      lst.deletex(k);
    } else if (s == "deleteFirst") {
      lst.pop_front();
    } else {
      lst.pop_back();
    }
  }
  lst.print();
  return 0;
}