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

#include <iostream>

using namespace std;

class List {

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

  Node *nil;

  void delete_(Node *node) {
    if (node == nil)
      return;
    node->next->prev = node->prev;
    node->prev->next = node->next;
    delete node;
  }

public:
  List() {
    nil = new Node{-1};
    nil->prev = nil;
    nil->next = nil;
  }

  void insert(int x) {
    Node *node = new Node{x};
    node->prev = nil;
    node->next = nil->next;
    nil->next->prev = node;
    nil->next = node;
  }

  void delete_(int x) {
    Node *node = nil;
    while (node->key != x) {
      node = node->next;
      if (node == nil)
        break;
    }
    delete_(node);
  }

  void deleteFirst() { delete_(nil->next); }

  void deleteLast() { delete_(nil->prev); }

  void dump() {
    Node *node = nil->next;
    if (node != nil) {
      cout << node->key;
      node = node->next;
      while (node != nil) {
        cout << " " << node->key;
        node = node->next;
      }
      cout << endl;
    }
  }
};

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

  List L;

  string command;
  int x;
  while (n--) {
    cin >> command;
    if (command == "insert") {
      cin >> x;
      L.insert(x);
    } else if (command == "delete") {
      cin >> x;
      L.delete_(x);
    } else if (command == "deleteFirst") {
      L.deleteFirst();
    } else {
      L.deleteLast();
    }
  }

  L.dump();
}


Error: TLE

Fixed submission:

#include <iostream>
#include <list>

using namespace std;

int main() {

  int n, x;
  string com;
  list<int> list;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com[0] == 'i') {
      cin >> x;
      list.push_front(x);
    } else if (com[6] == 'F') {
      list.pop_front();
    } else if (com[6] == 'L') {
      list.pop_back();
    } else {
      cin >> x;
      for (auto it = list.begin(); it != list.end(); it++) {
        if (*it == x) {
          list.erase(it);
          break;
        }
      }
    }
  }

  int i = 0;
  for (auto x_ : list) {
    if (i++)
      cout << " ";
    cout << x_;
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

void printList() {
  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");
}

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 key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);

  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F')
          deleteFirst();
        else if (com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


Error: TLE

Fixed submission:

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

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->next;
  nil->next = x;
  x->prev = nil;
}

void printList() {
  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");
}

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 key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);

  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F')
          deleteFirst();
        else if (com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <memory>
#include <string>
#include <vector>
using namespace std;

int n;
list<long long int> linked_list;
void docommand(string command);
void print();

int main() {
  // freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char command[20];
    scanf("%s", command);
    docommand(command);
  }
  print();
  return 0;
}

void docommand(string command) {
  if (command == "insert") {
    long long int n;
    scanf("%lld", &n);
    linked_list.push_front(n);
  }
  if (command == "delete") {
    long long int n;
    scanf("%lld", &n);
    list<long long int>::iterator findit =
        std::find(linked_list.begin(), linked_list.end(), n);
    if (*findit == n) {
      linked_list.erase(findit);
    }
  }
  if (command == "deleteFirst") {
    linked_list.pop_front();
  }
  if (command == "deleteLast") {
    linked_list.pop_back();
  }
}
void print() {
  for (list<long long int>::iterator it = linked_list.begin();
       it != linked_list.end(); it++) {
    if (it != linked_list.begin()) {
      printf(" ");
    }
    printf("%lld", *it);
  }
  printf("\\n");
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <memory>
#include <string>
#include <vector>
using namespace std;

int n;
list<long long int> linked_list;
void docommand(string command);
void print();

int main() {
  // freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string command;
    cin >> command;
    docommand(command);
  }
  print();
  return 0;
}

void docommand(string command) {
  if (command == "insert") {
    long long int n;
    cin >> n;
    linked_list.push_front(n);
  }
  if (command == "delete") {
    long long int n;
    cin >> n;
    list<long long int>::iterator findit =
        std::find(linked_list.begin(), linked_list.end(), n);
    if (*findit == n) {
      linked_list.erase(findit);
    }
  }
  if (command == "deleteFirst") {
    linked_list.pop_front();
  }
  if (command == "deleteLast") {
    linked_list.pop_back();
  }
}
void print() {
  for (list<long long int>::iterator it = linked_list.begin();
       it != linked_list.end(); it++) {
    if (it != linked_list.begin()) {
      cout << ' ';
    }
    cout << *it;
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
struct node {
  node *prev;
  int key;
  node *next;
};
node L;
node *nil = &L;

node *find(int x) {
  node *i;
  for (i = nil; i->next->key != x && i->next != nil; i = i->next)
    ;
  return i->next;
}
void del(int x) {
  node *a;
  if (x == -1)
    a = nil->next;
  else if (x == -2)
    a = nil->prev;
  else
    a = find(x);
  if (a == nil)
    return;
  a->prev->next = a->next;
  a->next->prev = a->prev;
  free(a);
}
void in(int x) {
  node *a;
  a = (node *)malloc(sizeof(node));
  a->next = nil->next;
  nil->next->prev = a;
  nil->next = a;
  a->prev = nil;
  a->key = x;
}
int main() {
  int n;
  string s;
  L.prev = nil, L.next = nil;
  scanf("%d\\n", &n);
  while (n--) {
    getline(cin, s);
    int t = 0;
    for (int i = 7; i < s.size(); i++)
      t *= 10, t += s[i] - '0';
    if (s[0] == 'i')
      in(t);
    else {
      if (s[6] == 'F')
        del(-1);
      else if (s[6] == 'L')
        del(-2);
      else
        del(t);
    }
  }
  node *i;
  for (i = nil; i->next->next != nil; i = i->next)
    cout << i->next->key << ' ';
  cout << i->next->key << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
struct node {
  node *prev;
  int key;
  node *next;
};
node L;
node *nil = &L;

node *find(int x) {
  node *i;
  for (i = nil; i->next->key != x; i = i->next)
    ;
  return i->next;
}
void del(int x) {
  node *a;
  if (x == -1)
    a = nil->next;
  else if (x == -2)
    a = nil->prev;
  else
    a = find(x);
  a->prev->next = a->next;
  a->next->prev = a->prev;
  free(a);
}
void in(int x) {
  node *a;
  a = (node *)malloc(sizeof(node));
  a->next = nil->next;
  nil->next->prev = a;
  nil->next = a;
  a->prev = nil;
  a->key = x;
}

int main() {
  int n;
  string s;
  L.prev = nil, L.next = nil;
  scanf("%d\\n", &n);
  while (n--) {
    getline(cin, s);
    if (s[0] == 'i')
      in(s[7] - '0');
    else {
      if (s[6] == 'F')
        del(-1);
      else if (s[6] == 'L')
        del(-2);
      else
        del(s[7] - '0');
    }
  }
  node *i;
  for (i = nil; i->next->next != nil; i = i->next)
    cout << i->next->key << ' ';
  cout << i->next->key << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void display(list<int> &lst) {
  if (!lst.empty()) {
    cout << lst.front();
    lst.pop_front();
  }
  for (auto element : lst) {
    cout << ' ' << element;
  }
  cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
  list<int> lst;
  int n = 0;
  cin >> n;
  for (int i = 0; i != n; ++i) {
    string command;
    cin >> command;
    if (command == "insert") {
      int x = 0;
      cin >> x;
      lst.push_front(x);
    } else if (command == "delete") {
      int x = 0;
      cin >> x;
      for (auto it = lst.begin(); it != lst.end(); ++it) {
        if (*it == x) {
          lst.erase(it);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      lst.pop_front();
    } else if (command == "deleteLast") {
      lst.pop_back();
    }
  }
  display(lst);
  return 0;
}

Error: TLE

Fixed submission:

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

void display(list<int> &lst) {
  if (!lst.empty()) {
    cout << lst.front();
    lst.pop_front();
  }
  for (auto element : lst) {
    cout << ' ' << element;
  }
  cout << endl;
}

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

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

typedef long long ll;
typedef unsigned long long ull;

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

  list<int> l;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string comm;
    int x;
    cin >> comm;
    if (comm == "insert") {
      cin >> x;
      l.push_front(x);
    } else if (comm == "delete") {
      cin >> x;
      for (auto it = l.begin(); it != l.end(); it++) {
        if (*it == x) {
          l.erase(it);
          break;
        }
      }
    } else if (comm == "deleteFirst") {
      l.pop_front();
    } else {
      l.pop_back();
    }
  }
  for (auto it = l.begin(); it != l.end(); it++) {
    if (it != l.begin())
      cout << ' ';
    cout << *it;
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  list<int> l;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string comm;
    int x;
    cin >> comm;
    if (comm == "insert") {
      cin >> x;
      l.push_front(x);
    } else if (comm == "delete") {
      cin >> x;
      for (auto it = l.begin(); it != l.end(); it++) {
        if (*it == x) {
          l.erase(it);
          break;
        }
      }
    } else if (comm == "deleteFirst") {
      l.pop_front();
    } else {
      l.pop_back();
    }
  }
  for (auto it = l.begin(); it != l.end(); it++) {
    if (it != l.begin())
      cout << ' ';
    cout << *it;
  }
  cout << endl;

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

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

int main(void) {
  int num, time;
  char str[100];
  list<int> l;

  scanf("%d", &time);

  for (int i = 0; i < time; i++) {
    scanf("%s", str);
    if (str[0] == 'i') {
      scanf("%d", &num);
      l.push_front(num);
    } else if (str[6] == 'F') {
      l.pop_front();
    } else if (str[6] == 'L') {
      l.pop_back();
    } else { // delete?????´???
      scanf("%d", &num);
      for (list<int>::iterator i = l.begin(); i != l.end(); i++) {
        if (num == *i) {
          l.erase(i);
          break;
        }
      }
    }
  }
  int j = 0;
  for (list<int>::iterator i = l.begin(); i != l.end(); i++) {
    if (j++)
      printf(" ");
    printf("%d", *i);
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int num, time;
  string str;
  list<int> l;

  cin >> time;

  for (int i = 0; i < time; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> num;
      l.push_front(num);
    } else if (str == "deleteFirst") {
      l.pop_front();
    } else if (str == "deleteLast") {
      l.pop_back();
    } else { // delete?????´???
      cin >> num;
      for (list<int>::iterator i = l.begin(); i != l.end(); i++) {
        if (num == *i) {
          l.erase(i);
          break;
        }
      }
    }
  }
  int j = 0;
  for (list<int>::iterator i = l.begin(); i != l.end(); i++) {
    if (j++)
      cout << " ";
    cout << *i;
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>  /* pow */
#include <stdio.h> /* printf */
#include <stdlib.h>
#include <string>
#include <vector>

void print_array(std::list<int> list) {
  int j = 0;
  for (std::list<int>::iterator i = list.begin(); i != list.end(); ++i) {
    if (j > 0)
      std::cout << " ";
    std::cout << *i;
    j++;
  }

  std::cout << std::endl;
}

void insert(std::list<int> &list, int a) { list.push_front(a); }

void deleteValue(std::list<int> &list, int a) {
  for (std::list<int>::iterator i = list.begin(); i != list.end(); ++i) {
    if (*i == a) {
      list.erase(i);
      return;
    }
  }
}

void deleteFirst(std::list<int> &list) { list.pop_front(); }

void deleteLast(std::list<int> &list) { list.pop_back(); }

int main(void) {

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

  int num;
  std::cin >> num;

  std::list<int> list;

  for (int i = 0; i < num; i++) {
    std::string value;
    std::cin >> value;

    if (value == "insert") {
      int a;
      std::cin >> a;
      insert(list, a);
    } else if (value == "delete") {
      int a;
      std::cin >> a;
      deleteValue(list, a);
    } else if (value == "deleteFirst") {
      deleteFirst(list);
    } else if (value == "deleteLast") {
      deleteLast(list);
    }
  }

  print_array(list);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>  /* pow */
#include <stdio.h> /* printf */
#include <stdlib.h>
#include <string>
#include <vector>

void print_array(std::vector<int> list) {
  for (int i = 0; i < list.size(); ++i) {
    if (i > 0)
      std::cout << " ";
    std::cout << list[i];
  }
  std::cout << std::endl;
}

void insert(std::vector<int> &list, int a) { list.insert(list.begin(), a); }

void deleteValue(std::vector<int> &list, int a) {
  int i = 0;
  while (i < list.size()) {
    if (list[i] == a) {
      list.erase(list.begin() + i);
      return;
    }
    i++;
  }
}

void deleteFirst(std::vector<int> &list) { list.erase(list.begin()); }

void deleteLast(std::vector<int> &list) { list.pop_back(); }

int main(void) {

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

  int num;
  std::cin >> num;

  std::vector<int> list;

  for (int i = 0; i < num; i++) {
    std::string value;
    std::cin >> value;

    if (value == "insert") {
      int a;
      std::cin >> a;
      insert(list, a);
    } else if (value == "delete") {
      int a;
      std::cin >> a;
      deleteValue(list, a);
    } else if (value == "deleteFirst") {
      deleteFirst(list);
    } else if (value == "deleteLast") {
      deleteLast(list);
    }
  }

  print_array(list);

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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

int main() {

  int n;
  cin >> n;

  deque<int> deq;
  string str;
  int m;

  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> m;
      deq.push_front(m);
    } else if (str == "deleteFirst") {
      deq.pop_front();
    } else if (str == "deleteLast") {
      deq.pop_back();
    } else if (str == "delete") {
      // 一番めんどくさい処理なので、最後に書いた
      cin >> m;
      deque<int>::iterator itr = deq.begin();
      while (itr != deq.end()) {
        if (*itr == m) {
          deq.erase(itr);
          break;
        }
        itr++;
      }
    }
  }
  //
  // while(!deq.empty()){
  //     cout << *deq.begin() << " ";
  //     deq.pop_front();
  // }

  int d_s = deq.size();
  for (int i = 0; i < d_s; i++) {
    if (i == d_s - 1) {
      cout << *deq.begin() << endl;
      break;
    }
    cout << *deq.begin() << " ";
    deq.pop_front();
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>

using namespace std;

int main() {

  int n;
  cin >> n;
  vector<int> data;

  // data.end() には0文字(null文字？)が入っている

  string str;
  int m;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> m;
      data.push_back(m);
    } else if (str == "delete") {
      cin >> m;
      vector<int>::iterator itr = data.end();
      itr--;
      while (*itr != m) {
        itr--;
        if (itr == data.begin()) {
          break;
        }
      }
      if (*itr == m) {
        data.erase(itr);
      } else {
        break;
      }
    } else if (str == "deleteFirst") {
      data.erase(data.end() - 1);
    } else if (str == "deleteLast") {
      data.erase(data.begin());
    }
  }

  int d_s = data.size();
  for (int i = 0; i < d_s; i++) {
    if (i == d_s - 1) {
      cout << data.back() << endl;
      data.pop_back();
      break;
    }
    cout << data.back() << " ";
    data.pop_back();
  }

  // vector<int> data;
  // data.push_back(1);
  // data.push_back(10);
  // data.push_back(100);
  // data.erase(data.begin()+1);
  // cout << data.back() << endl;
  // data.pop_back();
  // cout << data.back() << endl;
  // // -> 100 1

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

  deque<int> d;
  int n;
  string cmd;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      int x;
      cin >> x;
      d.push_front(x);
    } else if (cmd == "delete") {
      int x;
      cin >> x;
      for (deque<int>::iterator i = d.begin(); i != d.end(); i++) {
        if (*i == x) {
          d.erase(i);
          break;
        }
      }
    } else if (cmd == "deleteFirst") {
      d.pop_front();
    } else {
      d.pop_back();
    }
  }
  for (deque<int>::iterator i = d.begin(); i != d.end() - 1; i++) {
    cout << *i << " ";
  }
  cout << d.back() << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  deque<int> d;
  int n;
  string cmd;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      int x;
      cin >> x;
      d.push_front(x);
    } else if (cmd == "delete") {
      int x;
      cin >> x;
      for (deque<int>::iterator i = d.begin(); i != d.end(); i++) {
        if (*i == x) {
          d.erase(i);
          break;
        }
      }
    } else if (cmd == "deleteFirst") {
      d.pop_front();
    } else {
      d.pop_back();
    }
  }
  for (deque<int>::iterator i = d.begin(); i != d.end() - 1; i++) {
    cout << *i << " ";
  }
  cout << d.back() << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  list<int> lst;
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string query;
  int key;
  list<int>::iterator itr;
  while (n--) {
    cin >> query;
    if (query == "insert") {
      cin >> key;
      lst.push_front(key);
    }
    if (query == "delete") {
      cin >> key;
      for (itr = lst.begin(); itr != lst.end(); itr++) {
        if (*itr == key) {
          lst.erase(itr);
          break;
        }
      }
    }
    if (query == "deleteFirst")
      lst.pop_front();
    if (query == "deleteLast")
      lst.pop_back();
  }
  for (itr = lst.begin(); itr != --lst.end(); itr++) {
    cout << *itr << " ";
  }
  cout << *itr << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  list<int> lst;
  int n;
  cin >> n;
  string query;
  int key;
  list<int>::iterator itr;
  while (n--) {
    cin >> query;
    if (query == "insert") {
      cin >> key;
      lst.push_front(key);
    } else if (query == "delete") {
      cin >> key;
      for (itr = lst.begin(); itr != lst.end(); itr++) {
        if (*itr == key) {
          lst.erase(itr);
          break;
        }
      }
    } else if (query == "deleteFirst")
      lst.pop_front();
    else if (query == "deleteLast")
      lst.pop_back();
  }
  for (itr = lst.begin(); itr != --lst.end(); itr++) {
    cout << *itr << " ";
  }
  cout << *itr << endl;
  return 0;
}