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

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

int main() {
  int n;
  string x;
  int ptime;
  list<int> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == "insert") {
      int tmp = 0;
      cin >> tmp;
      a.push_front(tmp);
    }
    if (x == "delete") {
      int tmp = 0;
      cin >> tmp;
      for (list<int>::iterator itr = a.begin(); itr != a.end(); ++itr) {
        if (*itr == tmp) {
          a.erase(itr);
          break;
        }
      }
    }
    if (x == "deleteFirst") {
      a.pop_front();
    }
    if (x == "deleteLast") {
      a.pop_back();
    }
  }
  for (list<int>::iterator itr = a.begin(); itr != a.end();) {
    cout << *itr;
    ++itr;
    if (itr != a.end()) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

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

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

Node *nil;

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

void insert(int key) {
  Node *in;
  in = (Node *)malloc(sizeof(Node));

  in->key = key;
  in->next = nil->next;
  in->prev = nil;
  nil->next = in;
  in->next->prev = in;
}

void delFirst(void) {
  nil->next = nil->next->next;
  nil->next->prev = nil;
}

/*
void delLast(void){
  Node* i;

  for(i=nil; i->next!=nil; i=i->next);
  i->prev->next=nil;
}
*/

void delLast(void) {
  nil->prev = nil->prev->prev;
  nil->prev->next = nil;
}

void del(int key) {
  Node *i;

  for (i = nil->next; i != nil; i = i->next) {
    if (i->key == key) {
      i->next->prev = i->prev;
      i->prev->next = i->next;
      break;
    }
  }
}

void print(void) {
  for (Node *i = nil->next; i != nil; i = i->next) {
    if (i->prev == nil)
      printf("%d", i->key);
    else
      printf(" %d", i->key);
  }
  printf("\\n");
}

int main(void) {
  int n, num;
  char com[12];

  initialize();

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", com, &num);
    if (com[0] == 'i')
      insert(num);
    else if (com[6] == 'F')
      delFirst();
    else if (com[6] == 'L')
      delLast();
    else
      del(num);
  }

  print();

  return 0;
}


Error: TLE

Fixed submission:

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

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

Node *nil;

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

void insert(int key) {
  Node *in;
  in = (Node *)malloc(sizeof(Node));

  in->key = key;
  in->next = nil->next;
  in->prev = nil;
  nil->next = in;
  in->next->prev = in;
}

void delFirst(void) {
  nil->next = nil->next->next;
  nil->next->prev = nil;
}

void delLast(void) {
  Node *i;

  for (i = nil; i->next != nil; i = i->next)
    ;
  i->prev->next = nil;
}

void del(int key) {
  Node *i;

  for (i = nil->next; i != nil; i = i->next) {
    if (i->key == key) {
      i->next->prev = i->prev;
      i->prev->next = i->next;
      break;
    }
  }
}

void print(void) {
  for (Node *i = nil->next; i != nil; i = i->next) {
    if (i->prev == nil)
      printf("%d", i->key);
    else
      printf(" %d", i->key);
  }
  printf("\\n");
}

int main(void) {
  int n, num;
  char com[12];

  initialize();

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", com, &num);
    if (com[0] == 'i')
      insert(num);
    else if (com[6] == 'F')
      delFirst();
    else if (com[6] == 'L')
      delLast();
    else
      del(num);
  }

  print();

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

#include <iostream>
#include <list>
#include <stdio.h>
using namespace std;
int n;
list<int> l;
list<int>::iterator point(int a) {
  for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
    if (*itr == a)
      return itr;
  }
  return l.end();
}
int main() {
  int n;
  cin >> n;
  char s[20];
  int num;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s[0] == 'i') {
      cin >> num;
      l.push_front(num);
    } else if (s[6] == 'F')
      l.pop_front();
    else if (s[6] == 'L')
      l.pop_back();
    else {
      cin >> num;
      if (point(num) != l.end())
        l.erase(point(num));
    }
  }
  list<int>::iterator enditr = l.end();
  enditr--;
  for (list<int>::iterator itr = l.begin(); itr != enditr; itr++) {
    cout << *itr << " ";
  }
  cout << *enditr << endl;
  cin >> s;
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <list>
#include <stdio.h>
using namespace std;
int n;
list<int> l;
list<int>::iterator point(int a) {
  for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
    if (*itr == a)
      return itr;
  }
  return l.end();
}
int main() {
  int n;
  cin >> n;
  char s[20];
  for (int i = 0; i < n; i++) {
    int num;
    cin >> s;
    if (s[0] == 'i') {
      scanf("%d", num);
      l.push_front(num);
    } else if (s[6] == 'F')
      l.pop_front();
    else if (s[6] == 'L')
      l.pop_back();
    else {
      scanf("%d", num);
      if (point(num) != l.end())
        l.erase(point(num));
    }
  }
  list<int>::iterator enditr = l.end();
  enditr--;
  for (list<int>::iterator itr = l.begin(); itr != enditr; itr++) {
    cout << *itr << " ";
  }
  cout << *enditr << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (i = a; i < b; i++)
#define rloop(i, a, b) for (i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int main(void) {
  int n, i, j, k;
  cin >> n;
  list<int> l;
  char s[20];
  int x;
  loop(i, 0, n) {
    scanf("%s", s);
    if (s[0] == 'i') {
      scanf("%d", &x);
      l.push_front(x);
    } else if (s[6] == 'F') {
      l.pop_front();
    } else if (s[6] == 'L') {
      l.pop_back();
    } else {
      scanf("%d", &x);
      auto itr = l.begin();
      loop(j, 0, l.size()) {
        if (*itr == x) {
          l.erase(itr);
          break;
        }
        itr++;
      }
    }
  }
  if (!l.empty()) {
    printf("%d", *l.begin());
    l.pop_front();
  }
  while (!l.empty()) {
    printf(" %d", *l.begin());
    l.pop_front();
  }
  cout << "\\n";
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <deque>
#include <iostream>

int main(int argc, char const *argv[]) {

  int N;
  std::deque<int> que;
  std::cin >> N;
  std::string cmd;
  int key;

  for (int i = 0; i < N; ++i) {
    if (std::cin >> cmd) {
      if (cmd == "insert") {
        std::cin >> key;
        que.push_front(key);
      } else if (cmd == "delete") {
        std::cin >> key;
        for (int j = 0; j < que.size(); ++j) {
          if (que[j] == key) {
            que.erase(que.begin() + j);
            break;
          }
        }
      } else if (cmd == "deleteFirst") {
        que.pop_front();
      } else if (cmd == "deleteLast") {
        que.pop_back();
      } else {
        // exception
      }
    }
  }

  for (int i = 0; i < que.size(); ++i) {
    std::cout << que[i];
    if (i < que.size() - 1)
      std::cout << " ";
  }
  std::cout << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <deque>
#include <iostream>

int main(int argc, char const *argv[]) {

  int N;
  std::deque<int> que;
  std::cin >> N;

  for (int i = 0; i < N; ++i) {
    std::string cmd;
    int key;
    if (std::cin >> cmd) {
      if (cmd == "insert") {
        std::cin >> key;
        que.push_front(key);
      } else if (cmd == "delete") {
        std::cin >> key;
        for (int j = 0; j < que.size(); ++j) {
          if (que[j] == key) {
            que.erase(que.begin() + j);
            break;
          }
        }
      } else if (cmd == "deleteFirst") {
        que.pop_front();
      } else if (cmd == "deleteLast") {
        que.pop_back();
      } else {
        // exception
      }
    }
  }

  for (int i = 0; i < que.size(); ++i) {
    std::cout << que[i];
    if (i < que.size() - 1)
      std::cout << " ";
  }
  std::cout << std::endl;

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

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

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;

  std::string command;
  int key;
  std::deque<int> l;
  for (int i = 0; i < n; i++) {
    std::cin >> command;
    if (command[0] == 'i') {
      std::cin >> key;
      l.push_front(key);
    } else if (command.length() == 6) {
      std::cin >> key;
      std::deque<int>::iterator itr = find(l.begin(), l.end(), key);
      if (itr != l.end())
        l.erase(itr);
    } else if (command[6] == 'F') {
      l.pop_front();
    } else if (command[6] == 'L') {
      l.pop_back();
    }
  }

  for (int i = 0; i < l.size() - 1; i++) {
    std::cout << l[i] << " ";
  }
  std::cout << l.back() << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;

  std::string command;
  int key;
  std::deque<int> l;
  for (int i = 0; i < n; i++) {
    std::cin >> command;
    if (command == "insert") {
      std::cin >> key;
      l.push_front(key);
    } else if (command == "delete") {
      std::cin >> key;
      std::deque<int>::iterator itr = find(l.begin(), l.end(), key);
      if (itr != l.end())
        l.erase(itr);
    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
  }

  for (int i = 0; i < l.size() - 1; i++) {
    std::cout << l[i] << " ";
  }
  std::cout << l.back() << std::endl;

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

#include <iostream>
#include <stdlib.h>
using namespace std;
struct List {
  int key;
  List *prev, *next;
};
List *head;
void init() {
  head = (List *)malloc(sizeof(List));
  head->prev = head;
  head->next = head;
}
void insert(int key) {
  List *x = (List *)malloc(sizeof(List));
  x->key = key;
  x->next = head->next;
  head->next->prev = x;
  head->next = x;
  x->prev = head;
}
List *searchList(int key) {
  List *p = head->next;
  while (p != head && p->key != key) {
    p = p->next;
  }
  return p;
}
void deleteList(List *t) {
  if (t == head)
    return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
void deleteKey(int key) { deleteList(searchList(key)); }
void deleteFirst() { deleteList(head->next); }
void deleteLast() { deleteList(head->prev); }
void show() {
  List *p = head->next;
  int i = 0;
  while (p != head) {
    if (i > 0)
      cout << " ";
    cout << p->key;
    p = p->next;
    i++;
  }
  cout << endl;
}
int main() {
  int n;
  string command;
  int x;

  init();

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command == "insert") {
      cin >> x;
      insert(x);
    } else if (command == "delete") {
      cin >> x;
      deleteKey(x);
    } else if (command == "deleteFirst")
      deleteFirst();
    else
      deleteLast();
  }
  show();
  return 0;
}

Error: TLE

Fixed submission:

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

#define prinf printf
#define SIZE 1000000
int main() {
  int n;
  char order[20];
  int key;
  int list[SIZE];
  int first = SIZE - 1;
  int i, j;
  int flag = 0;

  scanf("%d", &n);

  for (j = 0; j < n; j++) {
    scanf("%s ", order);
    if (strcmp(order, "insert") == 0) {
      scanf("%d", &key);
      list[first] = key;
      first--;
    } else if (strcmp(order, "delete") == 0) {
      scanf("%d", &key);
      for (i = first + 1; i < SIZE; i++) {
        if (list[i] == key) {
          list[i] = -1;
          break;
        }
      }
    } else if (strcmp(order, "deleteFirst") == 0) {
      for (i = first + 1; i < SIZE; i++) {
        if (list[i] != -1) {
          list[i] = -1;
          break;
        }
      }
    } else if (strcmp(order, "deleteLast") == 0) {
      for (i = SIZE - 1; i > first; i--) {
        if (list[i] != -1) {
          list[i] = -1;
          break;
        }
      }
    }
  }

  for (i = first + 1; i < SIZE; i++) {
    if (list[i] != -1) {
      if (flag == 0) {
        printf("%d", list[i]);
        flag = 1;
      } else {
        prinf(" %d", list[i]);
      }
    }
  }
  printf("\\n");

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

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

void Command(list<int> &X, string &c) {
  if (c == "insert") {
    int d;
    cin >> d;
    X.push_front(d);
  } else if (c == "delete") {
    int d;
    cin >> d;
    list<int>::iterator itr = X.begin();
    while (*itr != d && itr != X.end()) {
      itr++;
    }
    if (itr != X.end()) {
      X.erase(itr);
    }
  } else if (c == "deleteFirst") {
    X.pop_front();
  } else if (c == "deleteLast") {
    X.pop_back();
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  list<int> X;
  for (int i = 0; i < n; i++) {
    string c;
    cin >> c;
    Command(X, c);
  }
  list<int>::iterator it = X.begin();
  list<int>::iterator end = X.end();
  end--;
  while (it != end) {
    cout << *it << ' ';
    it++;
  }
  cout << *end << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

void Command(list<int> &X, string &c) {
  if (c == "insert") {
    int d;
    cin >> d;
    X.push_front(d);
  } else if (c == "delete") {
    int d;
    cin >> d;
    list<int>::iterator itr = X.begin();
    while (*itr != d && itr != X.end()) {
      itr++;
    }
    if (itr != X.end()) {
      X.erase(itr);
    }
  } else if (c == "deleteFirst") {
    X.pop_front();
  } else if (c == "deleteLast") {
    X.pop_back();
  }
}

int main() {
  int n;
  cin >> n;
  list<int> X;
  for (int i = 0; i < n; i++) {
    string c;
    cin >> c;
    Command(X, c);
  }
  list<int>::iterator it = X.begin();
  list<int>::iterator end = X.end();
  end--;
  while (it != end) {
    cout << *it << ' ';
    it++;
  }
  cout << *end << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, x, ans[2000100] = {-1}, a = 2000000, b = 2000001;
  string command;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> command;
    if (command == "insert") {
      cin >> x;
      ans[a] = x;
      --a;
    } else if (command == "delete") {
      cin >> x;
      int pnt = -1;
      for (int j = 0; j < b; ++j) {
        if (ans[j] == x) {
          pnt = j;
          break;
        }
      }
      if (pnt >= 0) {
        ans[pnt] = -1;
        if (pnt == b - 1)
          --b;
        if (pnt == a + 1)
          ++a;
      }
    } else if (command == "deleteFirst") {
      ans[a + 1] = -1;
      ++a;
    } else if (command == "deleteLast") {
      ans[b - 1] = -1;
      --b;
    }
  }
  for (int i = a + 1; i < b; ++i) {
    if (ans[i] != -1) {
      if (i > a + 1)
        cout << ' ';
      cout << ans[i];
    }
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, x, p = 0, ans[2000100];
  string command;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> command;
    if (command == "insert") {
      cin >> x;
      for (int j = p - 1; j >= 0; --j)
        ans[j + 1] = ans[j];
      ans[0] = x;
      ++p;
    } else if (command == "delete") {
      cin >> x;
      int pnt = -1;
      for (int j = 0; j < p; ++j) {
        if (ans[j] == x) {
          pnt = j;
          break;
        }
      }
      if (pnt >= 0) {
        for (int j = pnt; j < p; ++j)
          ans[j] = ans[j + 1];
        ans[p - 1] = -1;
        --p;
      }
    } else if (command == "deleteFirst") {
      for (int j = 0; j < p - 1; ++j)
        ans[j] = ans[j + 1];
      ans[p - 1] = -1;
      --p;
    } else if (command == "deleteLast") {
      ans[p - 1] = -1;
      --p;
    }
  }
  for (int i = 0; i < p; ++i) {
    if (ans[i] == -1)
      break;
    if (i)
      cout << ' ';
    cout << ans[i];
  }
  cout << endl;

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

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

#define NMAX 2000000 + 10
using namespace std;

int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  string inp;
  int x;
  list<int> data;
  list<int>::iterator iter, fun;

  cin >> n;

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

    if (inp[6] == 'F')
      data.pop_front();
    else if (inp[6] == 'L')
      data.pop_back();
    else {
      cin >> x;
      if (inp[0] == 'i')
        data.push_front(x);
      else {
        fun = find(data.begin(), data.end(), x);
        if (fun != data.end())
          data.erase(fun);
      }
    }
  }

  iter = data.begin();
  cout << *iter;
  *iter++;
  while (iter != data.end()) {
    cout << " ";
    cout << *iter;
    iter++;
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define NMAX 2000000 + 10
using namespace std;

int main(void) {

  int n;
  string inp;
  int x;
  list<int> data;
  list<int>::iterator iter, fun;

  cin >> n;

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

    if (inp[0] == 'i') {
      cin >> x;
      data.push_front(x);
    } else if (inp[6] == 'F')
      data.pop_front();
    else if (inp[6] == 'L')
      data.pop_back();
    else {
      cin >> x;
      fun = find(data.begin(), data.end(), x);
      if (fun != data.end())
        data.erase(fun);
    }
  }

  iter = data.begin();
  cout << *iter;
  *iter++;
  while (iter != data.end()) {
    cout << " ";
    cout << *iter;
    iter++;
  }
  cout << endl;

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
struct node {
  struct node *prev;
  struct node *next;
  long key;
};
typedef struct node *NP;
NP MN(long);
void IN(NP);
void DN(NP);
void FI(long);
NP dummy;

int main() {
  long n, val;
  string op;

  scanf("%ld", &n);
  dummy = MN(0);

  while (n-- > 0) {
    cin >> op;
    scanf("%ld", &val);
    if (op == "insert") {
      IN(MN(val));
    } else {
      FI(val);
    }
  }

  for (NP n = dummy->next; n != dummy; n = n->next) {
    cout << n->key;
    if (n->next != dummy)
      printf(" ");
  }
  printf("\\n");

  return 0;
}

void FI(long value) {
  NP n;
  dummy->key = value;
  for (n = dummy->next;; n = n->next) {
    if (n->key == value)
      break;
  }
  if (n != dummy)
    DN(n);
}

void DN(NP th) {
  th->prev->next = th->next;
  th->next->prev = th->prev;
  th->prev = th->next = th;
  free(th);
}

void IN(NP newn) {
  newn->next = dummy->next;
  newn->next->prev = newn;
  dummy->next = newn;
  newn->prev = dummy;
}

NP MN(long key) {
  NP n = (NP)malloc(sizeof(struct node));
  n->prev = n;
  n->next = n;
  n->key = key;
  return n;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
using namespace std;
struct node {
  struct node *prev;
  struct node *next;
  long key;
};
typedef struct node *NP;
NP MN(long);
void IN(NP);
void DN(NP);
void FI(long);
NP dummy;

int main() {
  long n, val;
  string op;

  cin >> n;
  dummy = MN(0);

  while (n-- > 0) {
    cin >> op >> val;
    if (op == "insert") {
      IN(MN(val));
    } else {
      FI(val);
    }
  }

  for (NP n = dummy->next; n != dummy; n = n->next) {
    cout << n->key;
    if (n->next != dummy)
      cout << " ";
  }
  cout << endl;

  return 0;
}

void FI(long value) {
  NP n;
  dummy->key = value;
  for (n = dummy->next;; n = n->next) {
    if (n->key == value)
      break;
  }
  if (n != dummy)
    DN(n);
}

void DN(NP th) {
  th->prev->next = th->next;
  th->next->prev = th->prev;
  th->prev = th->next = th;
  free(th);
}

void IN(NP newn) {
  newn->next = dummy->next;
  newn->next->prev = newn;
  dummy->next = newn;
  newn->prev = dummy;
}

NP MN(long key) {
  NP n = (NP)malloc(sizeof(struct node));
  n->prev = n;
  n->next = n;
  n->key = key;
  return n;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <string>
using namespace std;
#define ll long long
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string com;
  int key;
  list<ll> lst;
  list<ll>::iterator it, i = lst.end();
  while (n--) {
    cin >> com;
    if (com == "insert") {
      cin >> key;
      lst.push_front(key);
    } else if (com == "delete") {
      cin >> key;
      for (it = lst.begin(); it != i; it++) {
        if (*it == key) {
          lst.erase(it);
          break;
        }
      }
    } else if (com == "deleteFirst")
      lst.pop_front();
    else
      lst.pop_back();
  }
  i--;
  for (it = lst.begin(); it != i; it++)
    cout << *it << " ";
  cout << *i << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <string>
using namespace std;
int main() {
  string str;
  list<int> data;
  list<int>::iterator it, l;
  int n, x;
  cin >> n;
  while (n--) {
    cin >> str;
    if (str == "insert") {
      cin >> x;
      data.push_front(x);
    } else if (str == "delete") {
      cin >> x;
      for (it = data.begin(), l = data.end(); it != l; ++it) {
        if (*it == x) {
          data.erase(it);
          break;
        }
      }
    } else if (str == "deleteFirst")
      data.pop_front();
    else
      data.pop_back();
  }
  for (it = data.begin(), l = --data.end(); it != l; ++it)
    cout << *it << " ";
  cout << *it << endl;
  return 0;
}