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

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

int main() {
  int n;
  scanf("%d", &n);
  list<int> l;
  char com[20];
  for (int i = 0; i < n; i++) {
    scanf("%s", com);
    int x;
    if (!strcmp(com, "insert")) {
      scanf("%d", &x);
      l.push_front(x);
    } else if (!strcmp(com, "delete")) {
      scanf("%d", &x);
      for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
        if (*it == x) {
          l.erase(it);
          break;
        }
      }
    } else if (!strcmp(com, "deleteFirst")) {
      l.pop_front();
    } else if (!strcmp(com, "deleteLast")) {
      l.pop_back();
    }
  }
  for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
    cout << (it != l.begin() ? " " : "") << *it << flush;
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

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

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

Node *nil;

Node *listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}
void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (true) {
    if (cur == nil) {
      break;
    }
    if (isf++ > 0) {
      cout << " " << flush;
    }
    cout << cur->key << flush;
    cur = cur->next;
  }
  cout << endl;
}
void deleteNode(Node *t) {
  if (t == nil) {
    return;
  }
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
void deleteFirst() { deleteNode(nil->next); }
void deleteLast() { deleteNode(nil->prev); }
void deleteKey(int key) { deleteNode(listSearch(key)); }
void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
int main() {
  int n;
  cin >> n;
  init();
  char s[20];
  int key;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    if (!strcmp(s, "insert")) {
      scanf("%d", &key);
      insert(key);
    } else if (!strcmp(s, "delete")) {
      scanf("%d", &key);
      deleteKey(key);
    } else if (!strcmp(s, "deleteFirst")) {
      deleteFirst();
    } else {
      deleteLast();
    }
  }
  printList();
  return 0;
}


Error: TLE

Fixed submission:

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

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

Node *nil;

Node *listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}
void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (true) {
    if (cur == nil) {
      break;
    }
    if (isf++ > 0) {
      cout << " " << flush;
    }
    cout << cur->key << flush;
    cur = cur->next;
  }
  cout << endl;
}
void deleteNode(Node *t) {
  if (t == nil) {
    return;
  }
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
void deleteFirst() { deleteNode(nil->next); }
void deleteLast() { deleteNode(nil->prev); }
void deleteKey(int key) { deleteNode(listSearch(key)); }
void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
int main() {
  int n;
  cin >> n;
  init();
  string s;
  int key;
  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 {
      deleteLast();
    }
  }
  printList();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, key;
  char op[20];
  list<int> List;
  scanf("%d", &n);
  getchar();

  for (int i = 0; i < n; i++) {
    scanf("%s %d", op, &key);
    if (op[0] == 'i') {
      List.push_front(key);
    } else {
      if (strlen(op) > 6) {
        if (op[6] == 'F') {
          List.pop_front();
        } else {
          List.pop_back();
        }
      } else {
        for (list<int>::iterator it = List.begin(); it != List.end(); it++) {
          if (*it == key) {
            List.erase(it);
            break;
          }
        }
      }
    }
  }
  int flag = 0;
  for (list<int>::iterator it = List.begin(); it != List.end(); it++) {
    if (flag != 0)
      printf(" ");
    flag++;
    printf("%d", (*it));
  }
  printf("\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main() {
  list<ll> l;
  list<ll>::iterator it, it1;
  int N;
  cin >> N;
  while (N--) {
    string op;
    cin >> op;
    int x;
    if (op == "insert") {
      cin >> x;
      l.push_front(x);
    } else if (op == "delete") {
      cin >> x;
      for (it = l.begin(); it != l.end(); it++)
        if (*it == x) {
          l.erase(it);
          break;
        }
    } else if (op == "deleteFirst")
      l.pop_front();
    else
      l.pop_back();
  }
  for (it = l.begin(); it != l.end(); it++) {
    it1 = it;
    if (++it1 != l.end()) {
      cout << *it << ' ';
    } else
      cout << *it << '\\n';
  }
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  list<int> l;
  list<int>::iterator it;
  char op[10];
  int v, q;
  scanf("%d", &q);

  while (q--) {
    scanf("%s", op);
    if (op[0] == 'i') {
      scanf("%d", &v);
      l.push_front(v);
    } else if (strlen(op) == 10) // deleteLast
      l.pop_back();
    else if (strlen(op) == 11) // deleteFirst
      l.pop_front();
    else {
      scanf("%d", &v);

      for (it = l.begin(); it != l.end(); it++) {
        if (*it == v) {
          l.erase(it);
          break;
        }
      }
    }
  }

  it = l.begin();
  printf("%d", *it);
  it++;
  for (; it != l.end(); it++)
    printf(" %d", *it);
  printf("\\n");
  return 0;
}


Error: 0

Fixed submission:

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

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

Node *head;

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

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

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

Node *search(int x) {
  Node *p = head->next;
  while (p != head) {
    if (p->key == x) {
      return p;
    }
    p = p->next;
  }
  return NULL;
}

void deleteFirstNode() { deleteNode(head->next); }

void deleteLastNode() { deleteNode(head->prev); }

void deleteKey(int key) {
  Node *temp = search(key);
  deleteNode(temp);
}

void printList() {
  int i = 0;
  Node *p = head->next;
  while (true) {
    if (i == 1) {
      printf(" ");
    }
    i = 1;
    printf("%d", p->key);
    if (p->next == head)
      break;
    p = p->next;
  }
  printf("\\n");
}

int main() {

  init();
  char comand[20];
  int n, k;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%s%d", comand, &k);
    if (comand[0] == 'i') {
      insert(k);
    } else {
      if (strlen(comand) > 6) {
        if (comand[6] == 'F') {
          deleteFirstNode();
        } else {
          deleteLastNode();
        }
      } else {
        deleteKey(k);
      }
    }
  }
  printList();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define clr(a) memset(a, 0x00, sizeof(a))
#define Error(x) cout << #x << " = " << x << endl
#define iDEBUG freopen("in.txt", "r", stdin)
#define oDEBUG freopen("out.txt", "w", stdout)
#define pb push_back
#define pp pop_back
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define hi cout << "hi" << endl
typedef long long ll;

using namespace std;

int main() {
  _
      // iDEBUG;
      list<int>
          l;
  list<int>::iterator iter;

  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    if (str == "deleteFirst")
      l.pop_front();
    else if (str == "deleteLast")
      l.pop_back();
    else if (str == "insert") {
      cin >> x;
      l.push_front(x);
    } else {
      cin >> x;
      for (iter = l.begin(); iter != l.end(); iter++)
        if (*iter == x) {
          l.erase(iter);
          break;
        }
    }
  }
  for (iter = l.begin(); iter != l.end(); iter++) {
    if (iter != l.begin())
      cout << " ";
    cout << *iter;
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  list<int> li;
  list<int>::iterator it;
  vector<int> ans;
  int num;
  while (n--) {
    string action;
    cin >> action;
    if (action == "insert") {
      cin >> num;
      li.push_front(num);
    } else if (action == "delete") {
      cin >> num;
      for (it = li.begin(); it != li.end(); ++it) {
        if (num == *it) {
          li.erase(it);
          break;
        }
      }
    } else if (action == "deleteFirst") {
      li.pop_front();
    } else if (action == "deleteLast") {
      li.pop_back();
    }
    /*for(list<int>::iterator b=li.begin();b!=li.end();b++){
            cout<<*b<<" ";
    }*/
  }
  for (it = li.begin(); it != li.end(); ++it) {
    ans.push_back(*it);
  }
  for (int k = 0; k < ans.size(); k++) {
    cout << ans[k];
    if (k != ans.size() - 1)
      cout << " ";
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, num;
  cin >> n;
  list<int> l;
  list<int>::iterator iter; // 回傳一個 iterator
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    if (str == "insert") {
      cin >> num;
      l.push_front(num);
    } else if (str == "delete") {
      cin >> num;
      for (iter = l.begin(); iter != l.end(); iter++) {
        if (*iter == num) {
          l.erase(iter);
          break;
        }
      }

    } else if (str == "deleteFirst")
      l.pop_front();
    else if (str == "deleteLast")
      l.pop_back();
  }
  for (iter = l.begin(); iter != l.end(); iter++) {
    if (iter != l.begin())
      cout << " ";
    cout << *iter;
  }
  cout << "\\n";
}


Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
struct node {
  long long int value;
  struct node *pre;
  struct node *next;
};
typedef node Node;

int main() {
  long long int cases;
  scanf("%lld ", &cases);
  Node *head;
  Node *ptr;
  head = (Node *)malloc(sizeof(Node));
  ptr = head;
  head->pre = NULL;
  char sen[1000] = {0};
  cin.getline(sen, 1000);
  if (sen[0] == 'i') {
    long long int num;
    sscanf(sen, " %*s %lld", &num);
    ptr->value = num;
  }
  while ((cases--) != 1) {
    char sen[1000] = {0};
    cin.getline(sen, 1000);
    if (sen[0] == 'i') {
      Node *tmp;
      tmp = (Node *)malloc(sizeof(Node));
      tmp->pre = ptr;
      ptr->next = tmp;
      ptr = tmp;
      long long int num;
      sscanf(sen, " %*s %lld", &num);
      ptr->value = num;
      ptr->next = NULL;
    } else if (sen[6] == 'F') {
      head->next->pre = NULL;
      head = head->next;
    } else if (sen[6] == 'L') {
      ptr->pre->next = NULL;
      ptr = ptr->pre;
    } else {
      long long int target;
      sscanf(sen, " %*s %lld", &target);
      Node *tmp;
      tmp = ptr;

      while ((tmp->value) != target) {
        tmp = tmp->pre;
      }
      if ((tmp->value) == target) {
        if ((tmp->pre) != NULL) {
          tmp->next->pre = tmp->pre;
        } else {
          tmp->next->pre = NULL;
          head = tmp->next;
        }
        if ((tmp->pre) == NULL) {
        } else if ((tmp->next) == NULL) {
          tmp->pre->next = NULL;
        } else {
          tmp->pre->next = tmp->next;
        }
      }
    }
    // printf("QQ");
  }
  printf("%lld", ptr->value);
  ptr = ptr->pre;
  while (ptr != NULL) {
    printf(" %lld", ptr->value);
    ptr = ptr->pre;
  }
  printf("\\n");
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  int n, i, len, m, j, q, T = 0;
  char c[20];
  list<int> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> c;
    if (c[0] == 'i') {
      cin >> m;
      v.push_front(m);
    } else if (c[6] == 'L')
      v.pop_back();
    else if (c[6] == 'F')
      v.pop_front();
    else {
      cin >> m;
      for (list<int>::iterator it = v.begin(); it != v.end(); it++)
        if (*it == m) {
          v.erase(it);
          break;
        }
    }
  }
  i = 0;
  for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
    if (i++)
      cout << ' ';
    cout << *it;
  }
  cout << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>
using namespace std;
struct kz {
  int a;
  int b;
  int c;
};
kz p[000005];
char s[20];
int d;
int top = 0;
int head = 0;
int last = 1;
int fuck;
void in() {
  if (head == 0) {
    p[++top].a = d;
    p[top].b = -1;
  } else {
    p[++top].a = d;
    p[top].b = fuck;
    p[fuck].c = top;
    p[top].c = -1;
  }
  fuck = top;
  head = top;
  return;
}
void ts() {
  p[top].a = -1;
  p[top].b = -1;
  p[top].c = -1;
}
void deh() {
  if (p[head].b == -1) {
    ts();
  }
  head = p[head].b;
  p[head].c = -1;
  top = head;
  fuck = top;
  return;
}
void del() {
  if (p[last].c == -1) {
    ts();
  }
  last = p[last].c;
  p[last].b = -1;
  return;
}
void de() {
  for (int i = head; i; i = p[i].b) {
    if (p[i].a == d && i == head) {
      deh();
    } else if (p[i].a == d && i == last) {
      del();
    } else if (p[i].a == d) {
      p[p[i].b].c = p[i].c;
      p[p[i].c].b = p[i].b;
      return;
    }
  }
}
void pt() {
  int kg = 0;
  for (int i = head; i; i = p[i].b) {
    if (p[i].a == -1)
      break;
    if (kg > 0)
      printf(" ");
    printf("%d", p[i].a);
    ++kg;
    if (p[i].b == -1) {
      break;
    }
  }
  printf("\\n");
  return;
}
int main() {
  // freopen("ans.out","w",stdout);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    if (strlen(s) < 7) {
      scanf("%d", &d);
    }
    if (s[0] == 'i') {
      in();
    } else if (s[0] == 'd') {
      if (strlen(s) > 6) {
        if (s[6] == 'F') {
          deh();
        } else if (s[6] == 'L') {
          del();
        }
      } else
        de();
    }
  }
  pt();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

struct node {
  int key;
  node *left;
  node *right;
};

node *nil;

void link(node *l, node *r) {
  l->right = r;
  r->left = l;
}

void init() {
  nil = (node *)malloc(sizeof(node));
  nil->right = nil;
  nil->left = nil;
}

node *search(int key) {
  node *cur = nil->right;
  while (cur != nil && cur->key != key) {
    cur = cur->right;
  }
  return cur;
}

void insert(int key) {
  node *x = (node *)malloc(sizeof(node));
  x->key = key;

  link(x, nil->right);
  link(nil, x);
}

void deletenode(node *cur) {
  if (cur == nil)
    return;
  link(cur->left, cur->right);
  free(cur);
}

void deleteFirst() { deletenode(nil->right); }

void deleteLast() { deletenode(nil->left); }

void deleteKey(int key) { deletenode(search(key)); }

void printlist() {
  node *cur;
  for (cur = nil->right; cur->right != nil; cur = cur->right) {
    printf("%d ", cur->key);
  }
  printf("%d\\n", cur->key);
}

int main() {
  char cmd[25];
  init();
  int kase;
  int key;
  scanf("%d", &kase);

  while (kase--) {
    scanf("%s", cmd);
    if (cmd[0] == 'i') {
      scanf("%d", &key);
      insert(key);
    } else if (cmd[0] == 'd') {
      if (strlen(cmd) <= 6) {
        scanf("%d", &key);
        deleteKey(key);
      }
      if (strlen(cmd) > 6) {
        if (cmd[6] == 'F') {
          deleteFirst();
        } else if (cmd[6] == 'L') {
          deleteLast();
        }
      }
    }
  }
  printlist();
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int inf = 1000000;

int lleft[inf], lright[inf];
int first = inf, last = inf;

void link(int l, int r) {
  lright[l] = r;
  lleft[r] = l;
}

void init() {
  for (int i = 0; i < inf; i++) {
    lleft[i] = lright[i] = inf;
  }
  lleft[first] = last;
  lright[last] = first;
}

int main() {
  char cmd[25];
  int key;

  init();
  int kase;
  scanf("%d", &kase);

  while (kase--) {
    scanf("%s", cmd);
    //        scanf("%d",&key);

    if (cmd[0] == 'i') {
      scanf("%d", &key);
      link(key, first);
      first = key;
      last = lleft[first];

      //            int i;
      //            for(i = first; lright[i] != inf; i = lright[i]) {}
      //            last = i;
    } else if (cmd[0] == 'd') {
      if (strlen(cmd) > 6) {
        if (cmd[6] == 'F') {
          // delete first
          link(lleft[first], lright[first]);
          first = lright[first];
        } else if (cmd[6] == 'L') {
          // delete last
          link(lleft[last], lright[last]);
          last = lleft[last];
        }
      }
      if (strlen(cmd) <= 6) {
        scanf("%d", &key);
        link(lleft[key], lright[key]);
      }
    }
  }
  //    cout << first << endl;
  //    int i;
  //    for(i = first; lright[i] != inf; i = lright[i]){
  //        printf("%d ",i);
  //    }
  //    last = i;
  //    printf("%d\\n",i);

  int i;
  for (i = first; lright[i] != last; i = lright[i]) {
    printf("%d ", i);
  }
  printf("%d\\n", i);
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  list<int> list1;
  int n, tmp;
  string string1;
  cin >> n;
  while (n--) {
    cin >> string1;
    if (string1 == "insert") {
      cin >> tmp;
      list1.push_front(tmp);
    } else if (string1 == "delete") {
      cin >> tmp;
      auto itend = list1.end();
      for (auto it = list1.begin(); it != itend; it++) {
        if (*it == tmp) {
          list1.erase(it);
          break;
        }
      }
    } else if (string1 == "deleteLast") {
      list1.pop_back();
    } else if (string1 == "deleteFirst") {
      list1.pop_front();
    }
  }
  int i = 0;
  for (auto &&item : list1) {
    if (i++)
      printf(" ");
    printf("%d", item);
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

Node *head;

void setting() {
  head = (Node *)malloc(sizeof(Node));
  head->prev = head;
  head->next = head;
}

Node *serachlist(int key) {
  Node *s = head->next;
  while (s != NULL && s->key != key) {
    s = s->next;
  }
  return s;
}

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

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

void deletefirst() { deletelist(head->next); }

void deletelast() { deletelist(head->prev); }

void deletekey(int key) { deletelist(serachlist(key)); }

void print() {
  Node *t = head->next;
  int a = 0;
  while (1) {
    if (t == head)
      break;
    if (a++ > 0)
      printf(" ");
    printf("%d", t->key);
    t = t->next;
  }
  printf("\\n");
}

int main() {
  int key, n, i;
  char com[20];
  while (scanf("%d", &n) != EOF) {

    setting();
    for (i = 0; i < n; i++) {
      scanf("%s%d", com, &key);
      if (com[0] == 'i') {
        insertlist(key);
      } else if (com[0] == 'd') {
        if (strlen(com) > 6) {
          if (com[6] == 'F')
            deletefirst();
          else if (com[6] == 'L')
            deletelast();
        } else
          deletekey(key);
      }
    }
    print();
  }
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

void print_list(list<int> &V) {
  for (list<int>::iterator it = V.begin(); it != V.end(); it++) {
    if (it == V.begin()) {
      cout << *it;
    } else {
      cout << " " << *it;
    }
  }
  cout << endl;
}
int main(void) {
  ios_base::sync_with_stdio(false);

  list<int> V;

  int n;
  cin >> n;

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

void print_list(list<int> &V) {
  for (list<int>::iterator it = V.begin(); it != V.end(); it++) {
    if (it == V.begin()) {
      cout << *it;
    } else {
      cout << " " << *it;
    }
  }
  cout << endl;
}
int main(void) {
  list<int> V;

  int n;
  cin >> n;

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

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

  return 0;
}