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

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

using namespace std;

int main() {
  list<int> lst;

  int N;
  cin >> N;

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

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

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  list<int> lst;

  int N;
  cin >> N;

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

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

#include <cstdio>
#include <cstring>

struct dlist {
  int key;
  dlist *prev, *next;
  dlist(int key, dlist *prev, dlist *next) : key(key), prev(prev), next(next){};
  ~dlist() {
    this->next->prev = this->prev;
    this->prev->next = this->next;
  }
};

int main() {
  size_t n;
  scanf("%zu", &n);
  dlist sentinel(0, nullptr, nullptr);
  sentinel.prev = sentinel.next = &sentinel;
  for (size_t i = 0; i < n; i++) {
    char c[16];
    int key;
    scanf("%s", c);
    if (strcmp(c, "insert") == 0) {
      scanf("%d", &key);
      auto l = new dlist(key, &sentinel, sentinel.next);
      l->next->prev = l;
      l->prev->next = l;
    } else if (strcmp(c, "delete") == 0) {
      scanf("%d", &key);
      for (auto l = sentinel.next; l != &sentinel; l = l->next)
        if (l->key == key) {
          delete l;
          break;
        }
    } else if (strcmp(c, "deleteFirst") == 0)
      delete sentinel.next;
    else
      delete sentinel.prev;
  }
  if (sentinel.next != &sentinel) {
    printf("%d", sentinel.next->key);
    for (auto l = sentinel.next->next; l != &sentinel; l = l->next)
      printf(" %d", l->key);
    puts("");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

struct dlist {
  int key;
  dlist *prev, *next;
  dlist(int key, dlist *prev, dlist *next) : key(key), prev(prev), next(next){};
  ~dlist() {
    this->next->prev = this->prev;
    this->prev->next = this->next;
  }
};

int main() {
  size_t n;
  std::cin >> n;
  dlist sentinel(0, nullptr, nullptr);
  sentinel.prev = sentinel.next = &sentinel;
  for (size_t i = 0; i < n; i++) {
    std::string c;
    int key;
    std::cin >> c;
    if (c == "insert") {
      std::cin >> key;
      auto l = new dlist(key, &sentinel, sentinel.next);
      l->next->prev = l;
      l->prev->next = l;
    } else if (c == "delete") {
      std::cin >> key;
      for (auto l = sentinel.next; l != &sentinel; l = l->next)
        if (l->key == key) {
          delete l;
          break;
        }
    } else if (c == "deleteFirst") {
      delete sentinel.next;
    } else {
      delete sentinel.prev;
    }
  }
  if (sentinel.next != &sentinel) {
    std::cout << sentinel.next->key;
    for (auto l = sentinel.next->next; l != &sentinel; l = l->next)
      std::cout << ' ' << l->key;
    std::cout << std::endl;
  }
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  string s;
  int n, i, a;
  list<int> li;
  list<int>::iterator p = li.begin();
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> a;
      li.push_front(a);
    } else if (s == "delete") {
      cin >> a;
      p = find(li.begin(), li.end(), a);
      if (p != li.end())
        li.erase(p);

    } else if (s == "deleteFirst") {
      li.pop_front();
    } else if (s == "deleteLast") {
      li.pop_back();
    }
  }
  p = li.begin();

  while (p != li.end()) {
    cout << *p;
    p++;
    if (p != li.end())
      cout << " ";
    else
      cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  string s;
  int n, i, a;
  list<int> li;
  list<int>::iterator p = li.begin();
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> a;
      li.push_front(a);
    } else if (s == "delete") {
      cin >> a;
      p = find(li.begin(), li.end(), a);
      if (p != li.end())
        li.erase(p);

    } else if (s == "deleteFirst") {
      li.pop_front();
    } else if (s == "deleteLast") {
      li.pop_back();
    }
  }
  p = li.begin();

  while (p != li.end()) {
    cout << *p;
    p++;
    if (p != li.end())
      cout << " ";
    else
      cout << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.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 *listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

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

int main() {
  int n, key;
  char com[20];
  scanf("%d", &n);
  init();
  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);
      }
    }
  }
  Node *cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil)
      break;
    if (isf++ > 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\\n");
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.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 *listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

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

int main() {
  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);
      }
    }
  }
  Node *cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil)
      break;
    if (isf++ > 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\\n");
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <sstream>

using namespace std;

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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  list<int> data;
  list<int>::iterator it;
  int n;
  cin >> n;
  int x;
  string str;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> x;
      data.push_front(x);
    } else if (str == "delete") {
      cin >> x;
      for (it = data.begin(); it != data.end(); it++) {
        if (*it == x) {
          data.erase(it);
          break;
        }
      }
    } else if (str == "deleteFirst")
      data.pop_front();
    else
      data.pop_back();
  }
  it = data.begin();
  while (it != data.end()) {
    cout << *it;
    it++;
    (it == data.end()) ? cout << endl : cout << " ";
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <sstream>

using namespace std;

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

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)

using namespace std;
typedef long long int lint;

//***** Main Program *****

int main() {
  int n;
  cin >> n;
  deque<int> dq;
  Loop(i, n) {
    char cmd[20];
    int x;
    scanf("%s", cmd);
    if (cmd[0] == 'i') {
      scanf("%d", &x);
      dq.push_front(x);
    } else if (cmd[0] == 'd' && cmd[6] == '\\0') {
      scanf("%d", &x);
      Loop(i, dq.size()) {
        if (dq[i] == x) {
          dq.erase(dq.begin() + i);
          break;
        }
      }
    } else if (cmd[6] == 'F')
      dq.pop_front();
    else if (cmd[6] == 'L')
      dq.pop_back();
    else
      return -1;
  }
  while (dq.size() > 1) {
    printf("%d ", dq.front());
    dq.pop_front();
  }
  if (dq.size() > 0)
    cout << dq.front() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)

using namespace std;
typedef long long int lint;

//***** Main Program *****

int main() {
  int n;
  cin >> n;
  list<int> lst;
  Loop(i, n) {
    char cmd[20];
    int x;
    scanf("%s", cmd);
    if (cmd[0] == 'i') {
      scanf("%d", &x);
      lst.push_front(x);
    } else if (cmd[0] == 'd' && cmd[6] == '\\0') {
      scanf("%d", &x);
      stack<int> stk;
      while (!lst.empty() && lst.front() != x) {
        stk.push(lst.front());
        lst.pop_front();
      }
      if (!lst.empty())
        lst.pop_front();
      while (!stk.empty()) {
        lst.push_front(stk.top());
        stk.pop();
      }
    } else if (cmd[6] == 'F')
      lst.pop_front();
    else if (cmd[6] == 'L')
      lst.pop_back();
    else
      return -1;
  }
  while (lst.size() > 1) {
    printf("%d ", lst.front());
    lst.pop_front();
  }
  if (lst.size() > 0)
    cout << lst.front() << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  list<int> l;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    int k;
    cin >> s;
    if (s == "insert") {
      cin >> k;
      l.emplace_front(k);
    } else if (s == "delete") {
      cin >> k;
      auto it = find(l.begin(), l.end(), k);
      if (it == l.end())
        continue;
      l.erase(it);
    } else if (s == "deleteFirst") {
      l.pop_front();
    } else {
      l.pop_back();
    }
  }

  for (auto it = l.begin(); it != l.end(); it++) {
    cout << *it;
    if (it != --l.end()) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  list<int> l;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    int k;
    cin >> s;
    if (s == "insert") {
      cin >> k;
      l.emplace_front(k);
    } else if (s == "delete") {
      cin >> k;
      auto it = find(l.begin(), l.end(), k);
      if (it == l.end())
        continue;
      l.erase(it);
    } else if (s == "deleteFirst") {
      l.pop_front();
    } else {
      l.pop_back();
    }
  }

  for (auto it = l.begin(); it != l.end(); it++) {
    cout << *it;
    if (it != --l.end()) {
      cout << " ";
    }
  }
  cout << endl;

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

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

using namespace std;

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

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  list<int> L;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string com;
    cin >> com;
    if (com == "insert") {
      int x;
      cin >> x;
      L.push_front(x);
    }
    if (com == "delete") {
      int x;
      cin >> x;
      list<int>::iterator it;
      for (it = L.begin(); it != L.end(); it++) {
        if (x == *it) {
          L.erase(it);
          break;
        }
      }
    }
    if (com == "deleteFirst") {
      L.pop_front();
    }
    if (com == "deleteLast") {
      L.pop_back();
    }
  }
  for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
    if (it == L.begin()) {
      printf("%d", *it);
    } else {
      printf(" %d", *it);
    }
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef struct _list_ {
  struct _list_ *prev;
  int value;
  struct _list_ *next;
} list;

int main(void) {
  int max, count;
  vector<list> x(2000000);
  string a;

  x[0].value = -1;
  x[1].value = -1;
  x[0].next = &x[1];
  x[1].prev = &x[0];

  count = 1;

  cin >> max;

  for (int i = 0; i < max; i++) {
    cin >> a;

    if (a == "insert") {
      count++;
      cin >> x[count].value;
      x[count].prev = &x[0];
      x[count].next = x[0].next;
      x[0].next->prev = &x[count];
      x[0].next = &x[count];
    }

    else if (a == "delete") {
      list *nextl = x[0].next;
      int b;
      cin >> b;
      for (;;) {
        if (nextl->value == b) {
          nextl->prev->next = nextl->next;
          nextl->next->prev = nextl->prev;
          break;
        }
        if (nextl->value == -1)
          break;
        nextl = nextl->next;
      }
    }

    else if (a == "deleteFirst") {
      x[0].next->next->prev = &x[0];
      x[0].next = x[0].next->next;
    }

    else if (a == "deleteLast") {
      x[1].prev->prev->next = &x[1];
      x[1].prev = x[1].prev->prev;
    }
  }

  list *nextl = x[0].next;

  if (nextl->value != -1) {
    cout << nextl->value;
    nextl = nextl->next;
  }

  for (;;) {
    if (nextl->value == -1)
      break;
    cout << " " << nextl->value;
    nextl = nextl->next;
  }

  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

typedef struct _list_ {
  struct _list_ *prev;
  int value;
  struct _list_ *next;
} list;

int main(void) {
  int max, count;
  vector<list> x(100000);
  string a;

  x[0].value = -1;
  x[1].value = -1;
  x[0].next = &x[1];
  x[1].prev = &x[0];

  count = 1;

  cin >> max;

  for (int i = 0; i < max; i++) {
    cin >> a;

    if (a == "insert") {
      count++;
      cin >> x[count].value;
      x[count].prev = &x[0];
      x[count].next = x[0].next;
      x[0].next->prev = &x[count];
      x[0].next = &x[count];
    }

    else if (a == "delete") {
      list *nextl = x[0].next;
      int b;
      cin >> b;
      for (;;) {
        if (nextl->value == b) {
          nextl->prev->next = nextl->next;
          nextl->next->prev = nextl->prev;
          break;
        }
        if (nextl->value == -1)
          break;
        nextl = nextl->next;
      }
    }

    else if (a == "deleteFirst") {
      x[0].next->next->prev = &x[0];
      x[0].next = x[0].next->next;
    }

    else if (a == "deleteLast") {
      x[1].prev->prev->next = &x[1];
      x[1].prev = x[1].prev->prev;
    }
  }

  list *nextl = x[0].next;

  if (nextl->value != -1) {
    cout << nextl->value;
    nextl = nextl->next;
  }

  for (;;) {
    if (nextl->value == -1)
      break;
    cout << " " << nextl->value;
    nextl = nextl->next;
  }

  cout << endl;

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#define LEN 100005
using namespace std;
// list実装

int main() {
  list<int> l;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string c;
    cin >> c;
    if (c[0] == 'i') {
      int a;
      scanf("%d", &a);
      l.push_front(a);
    } else {
      if (c[6] == 'F') {
        l.pop_front();
      } else if (c[6] == 'L') {
        l.pop_back();
      } else {
        int a;
        scanf("%d", &a);
        for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
          if (*itr == a) {
            l.erase(itr);
            break;
          }
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
    if (i++)
      cout << " ";
    printf("%d", *itr);
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#define LEN 100005
using namespace std;
// list実装

int main() {
  list<int> l;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string c;
    cin >> c;
    if (c[0] == 'i') {
      int a;
      scanf("%d", &a);
      l.push_front(a);
    } else {
      if (c[6] == 'F') {
        l.pop_front();
      } else if (c[6] == 'L') {
        l.pop_back();
      } else {
        int a;
        scanf("%d", &a);
        for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
          if (*itr == a) {
            l.erase(itr);
            break;
          }
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
    if (i++)
      cout << " ";
    printf("%d", *itr);
  }
  cout << endl;

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

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

int main() {

  int n, t;
  scanf("%d", &n);
  list<int> V;
  char com[20];
  for (int i = 0; i < n; i++) {

    scanf("%s", com);

    if (com[0] == 'i') {
      scanf("%d", &t);
      V.push_front(t);

    } else if (com[6] == 'F') {
      V.pop_front();
      // deleteLast
    } else if (com[6] == 'L') {
      V.pop_back();
    } else if (com[0] == 'd') {
      scanf("%d", &t);
      for (list<int>::iterator it = V.begin(); it != V.end(); it++) {
        if (*it == t) {
          V.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;

  for (list<int>::iterator it = V.begin(); it != V.end(); it++) {
    if (i++)
      printf(" ");
    printf("%d", *it);
  }

  printf("\\n");

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  int n, t;
  scanf("%d", &n);
  list<int> V;
  char com[20];
  for (int i = 0; i < n; i++) {

    scanf("%s", com);

    if (com[0] == 'i') {
      scanf("%d", &t);
      V.push_front(t);

    } else if (com[6] == 'F') {
      V.pop_front();
      // deleteLast
    } else if (com[6] == 'L') {
      V.pop_back();
    } else if (com[0] == 'd') {
      scanf("%d", &t);
      for (list<int>::iterator it = V.begin(); it != V.end(); it++) {
        if (*it == t) {
          V.erase(it);
          break;
        }
      }
    }
  }
  int i = 1;

  for (list<int>::iterator it = V.begin(); it != V.end(); it++) {

    printf("%d", *it);
    if (i != V.size()) {
      printf(" ");
      i++;
    }
  }
  printf("\\n");

  return 0;
}