alexjercan/bugnet huggingface dataset:
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  list<int> l;
  int n;
  string cmd;
  int x;

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

Error: 0

Fixed submission:

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

int main() {
  list<int> l;
  int n;
  string cmd;
  int x;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> x;
      l.push_front(x);
    } else if (cmd == "delete") {
      cin >> x;
      l.erase(find(begin(l), end(l), x));
    } else if (cmd == "deleteFirst") {
      l.pop_front();
    } else {
      l.pop_back();
    }
  }
  for (auto it = l.begin(); it != l.end();) {
    cout << *it;
    it++;
    if (it == l.end()) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  // your code goes here
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;

  string command;
  int x;
  list<int> list;
  while (n--) {
    cin >> command;
    if (command == "insert") {
      cin >> x;
      list.push_front(x);
    } else if (command == "delete") {
      cin >> x;
      std::list<int>::iterator itr;
      for (itr = list.begin(); itr != list.end(); itr++) {
        if (*itr == x) {
          list.erase(itr);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      list.pop_front();
    } else if (command == "deleteLast") {
      list.pop_back();
    }
  }
  int size = list.size();
  for (int i = 0; i < size; i++) {
    if (i > 0)
      cout << " ";
    cout << list.front();
    list.pop_front();
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  // your code goes here
  int n;
  cin >> n;

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

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

using namespace std;

int main() {

  int n;
  scanf("%d", &n);

  list<int> L;

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

    if (s == "insert") {
      int v;
      scanf("%d", &v);
      L.push_front(v);
    } else if (s == "delete") {
      int v;
      scanf("%d", &v);
      for (auto itr = L.begin(); itr != L.end(); ++itr) {
        if (*itr == v) {
          L.erase(itr);
          break;
        }
      }
    } else if (s == "deleteFirst") {
      L.pop_front();
    } else {
      L.pop_back();
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  int n;
  cin >> n;

  list<int> L;

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

    if (s == "insert") {
      int v;
      scanf("%d", &v);
      L.push_front(v);
    } else if (s == "delete") {
      int v;
      scanf("%d", &v);
      for (auto itr = L.begin(); itr != L.end(); ++itr) {
        if (*itr == v) {
          L.erase(itr);
          break;
        }
      }
    } else if (s == "deleteFirst") {
      L.pop_front();
    } else {
      L.pop_back();
    }
  }

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

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

#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;

int main() {
  list<int> a;
  int b;
  scanf("%d", &b);
  for (int c = 0; c < b; c++) {
    string d;
    cin >> d;
    if (d == "insert") {
      int e;
      scanf("%d", &e);
      a.push_front(e);
    } else if (d == "deleteFirst")
      a.pop_front();
    else if (d == "deleteLast")
      a.pop_back();
    else {
      int g;
      cin >> g;
      auto h = a.end();
      for (auto k = a.begin(); k != a.end(); k++) {
        if ((*k) == g) {
          h = k;
          break;
        }
      }
      if (h != a.end())
        a.erase(h);
    }
  }
  for (auto k = a.begin(); k != a.end(); k++) {
    printf("%d", (*k));
    if (k != --a.end())
      printf(" ");
    else
      printf("\\n");
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;

int main() {
  list<int> a;
  int b;
  scanf("%d", &b);
  for (int c = 0; c < b; c++) {
    string d;
    cin >> d;
    if (d == "insert") {
      int e;
      scanf("%d", &e);
      a.push_front(e);
    } else if (d == "deleteFirst")
      a.pop_front();
    else if (d == "deleteLast")
      a.pop_back();
    else {
      int g;
      cin >> g;
      auto h = a.end();
      for (auto k = a.begin(); k != a.end(); k++) {
        if ((*k) == g) {
          h = k;
          break;
        }
      }
      if (h != a.end())
        a.erase(h);
    }
  }
  auto o = a.end();
  o--;
  for (auto k = a.begin(); k != o; k++) {
    printf("%d ", (*k));
  }
  printf("%d\\n", (*o));
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, num;
  string s;
  deque<int> de;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "deleteFirst") {
      de.pop_front();
      continue;
    } else if (s == "deleteLast") {
      de.pop_back();
      continue;
    }
    scanf("%d", &num);
    if (s == "insert") {
      de.push_front(num);
    } else if (s == "delete") {
      for (deque<int>::iterator ite = de.begin(); ite < de.end(); ite++) {
        if (*ite == num) {
          de.erase(ite);
          break;
        }
      }
    }
  }
  for (int i = 0; i < de.size(); i++) {
    if (i == de.size() - 1)
      cout << de[i] << endl;
    else
      printf("%d ", de[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, num;
  string s;
  deque<int> de;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "deleteFirst") {
      de.pop_front();
      continue;
    } else if (s == "deleteLast") {
      de.pop_back();
      continue;
    }
    cin >> num;
    if (s == "insert") {
      de.push_front(num);
    } else if (s == "delete") {
      for (deque<int>::iterator ite = de.begin(); ite < de.end(); ite++) {
        if (*ite == num) {
          de.erase(ite);
          break;
        }
      }
    }
  }
  for (int i = 0; i < de.size(); i++) {
    if (i == de.size() - 1)
      cout << de[i] << endl;
    else
      cout << de[i] << " ";
  }
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
using namespace std;
int main() {
  list<int> line;
  int code;
  char codename[11];
  int time;
  cin >> time;
  list<int>::iterator he;
  for (int i = 0; i < time; ++i) {
    cin >> codename;
    if (codename[6] == 'F')
      line.pop_front();
    else if (codename[6] == 'L')
      line.pop_back();
    else {
      cin >> code;
      if (codename[0] == 'i')
        line.push_front(code);
      else {
        line.push_back(code);
        for (he = line.begin(); *he != code; ++he)
          ;
        if (++he != line.end())
          line.erase(--he);
        line.pop_back();
      }
    }
  }
  int doll = line.back();
  line.pop_back();
  for (he = line.begin(); he != line.end(); ++he) {
    cout << *he << ' ';
  }
  cout << doll << endl;
  cin >> time;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  vector<int> line;
  int time;
  string order;
  int code;
  int he = 0;
  vector<int>::iterator place;
  cin >> time;
  for (int i = 0; i < time; ++i) {
    cin >> order;
    if (order == "deleteFirst") {
      while (true) {
        if (*(line.end() - 1) == -1) {
          line.pop_back();
        } else {
          line.pop_back();
          break;
        }
      }
    } else if (order == "deleteLast") {
      while (true) {
        if (*(line.begin() + he) == -1) {
          ++he;
        } else {
          ++he;
          break;
        }
      }
    } else {
      cin >> code;
      if (order == "insert") {
        line.push_back(code);
      } else {
        for (place = line.end() - 1;; --place) {
          if (*place == code) {
            *place = -1;
            break;
          } else if (place == line.begin() + he) {
            break;
          }
        }
      }
    }
  }
  for (place = line.end() - 1;; --place) {
    if (*place != -1) {
      cout << *place;
      break;
    }
  }
  if (place == line.begin() + he)
    goto END;
  for (place -= 1;; --place) {

    if (place == line.begin() + he) {
      if (*place != -1) {
        cout << " " << *place;
      }
      break;
    }
    if (*place != -1) {
      cout << " " << *place;
    }
  }
END:
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

Node *searchNode(int key) {
  Node *cur = nil->next;
  while (cur->key != key && cur != nil) {
    cur = cur->next;
  }
  return cur;
}

void deleteNode(Node *t) {
  if (t != nil) {
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
  }
}

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

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

int main(void) {
  int n, key, i;
  char command[20];
  std::cin >> n;
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
  Node *cur;

  for (i = 0; i < n; i++) {
    std::cin >> command;
    if (command[0] == 'i') {
      std::cin >> key;
      insertNode(key);
    } else {
      if (std::strlen(command) > 6) {
        if (command[6] == 'F')
          deleteFirst();
        else if (command[6] = 'L')
          deleteLast();
      } else {
        std::cin >> key;
        deleteNode(searchNode(key));
      }
    }
  }

  cur = nil->next;
  while (cur->next != nil) {
    std::printf("%d ", cur->key);
    cur = cur->next;
  }
  std::printf("%d\\n", cur->key);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

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

Node *nil;

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

Node *searchNode(int key) {
  Node *cur = nil->next;
  while (cur->key != key && cur != nil) {
    cur = cur->next;
  }
  return cur;
}

void deleteNode(Node *t) {
  if (t != nil) {
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
  }
}

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

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

int main(void) {
  int n, key, i;
  char command[20];
  std::cin >> n;
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
  Node *cur;

  for (i = 0; i < n; i++) {
    std::cin >> command;
    if (command[0] == 'i') {
      std::cin >> key;
      insertNode(key);
    } else {
      if (std::strlen(command) > 6) {
        if (command[6] == 'F')
          deleteFirst();
        else if (command[6] = 'L')
          deleteLast();
      } else {
        std::cin >> key;
        deleteNode(searchNode(key));
      }
    }
  }

  cur = nil->next;
  while (cur->next != nil) {
    std::cout << cur->key << " ";
    cur = cur->next;
  }
  std::cout << cur->key << std::endl;

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

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

int main() {
  int n, k;
  char s[15];
  list<int> l;

  scanf("%d", &n);

  while (n--) {
    scanf("%s", s);
    if (*s == 'i') {
      scanf("%d", &k);
      l.push_front(k);
      continue;
    }
    switch (*(s + 6)) {
    case 'F':
      l.pop_front();
      break;
    case 'L':
      l.pop_back();
      break;
    default:
      scanf("%d", &k);
      auto r = find(l.begin(), l.end(), k);
      if (r != l.end())
        l.erase(r);
    }
  }

  int &f = l.front();
  for (int &x : l)
    printf("%s%d", (&f == &x ? "" : " "), x);
  puts("");
}


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  char s[15];
  list<int> l;

  scanf("%d", &n);

  while (n--) {
    scanf("%s", s);
    if (*s == 'i') {
      scanf("%d", &k);
      l.push_front(k);
      continue;
    }
    switch (*(s + 6)) {
    case 'F':
      l.pop_front();
      break;
    case 'L':
      l.pop_back();
      break;
    default:
      scanf("%d", &k);
      l.erase(find(l.begin(), l.end(), k));
    }
  }

  int &f = l.front();
  for (int &x : l)
    printf("%s%d", (&f == &x ? "" : " "), x);
  puts("");
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct node {

  int key;
  node *next, *prev;
};

node *nil;

void insert_node(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 delete_node(node *t) {
  if (t == nil)
    return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

node *seach_node(int key) {
  node *seach = nil->next;
  while (1) {
    if (seach->key == key)
      break;
    if (seach == nil)
      break;
    seach = seach->next;
  }
  return seach;
}

void malloc_node() {
  nil = (node *)malloc(sizeof(node));
  nil->next = nil;
  nil->prev = nil;
}

int main() {

  int n;
  char str[20];
  int key;

  scanf("%d", &n);

  malloc_node();

  for (int i = 0; i < n; i++) {

    scanf("%s", str);
    if (str[0] == 'i' || strlen(str) == 6)
      scanf("%d", &key);

    // cout << str << " " << key << " " << i << " " << n << endl;

    if (str[0] == 'i') {
      insert_node(key);
    } else if (str[0] == 'd') {
      if (strlen(str) > 6) {
        if (str[6] == 'F')
          delete_node(nil->next);
        else if (str[6] == 'L')
          delete_node(nil->prev);
      } else
        delete_node(seach_node(key));
    }
  }

  node *ans = nil->next;
  int cnt = 0;
  while (ans != nil) {
    if (cnt > 0)
      printf(" ");
    cnt++;
    printf("%d", ans->key);
    ans = ans->next;
  }
  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

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

struct node {

  int key;
  node *next, *prev;
};

node *nil;

void insert_node(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 delete_node(node *t) {
  if (t == nil)
    return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

node *seach_node(int key) {
  node *seach = nil->next;
  while (1) {
    if (seach->key == key)
      break;
    seach = seach->next;
  }
  return seach;
}

void malloc_node() {
  nil = (node *)malloc(sizeof(node));
  nil->next = nil;
  nil->prev = nil;
}

int main() {

  int n;
  char str[20];
  int key;

  scanf("%d", &n);

  malloc_node();

  for (int i = 0; i < n; i++) {

    scanf("%s%d", str, &key);

    // cout << str << " " << key << " " << i << " " << n << endl;

    if (str[0] == 'i') {
      insert_node(key);
    } else if (str[0] == 'd') {
      if (strlen(str) > 6) {
        if (str[6] == 'F')
          delete_node(nil->prev);
        else if (str[6] == 'L')
          delete_node(nil->next);
      } else
        delete_node(seach_node(key));
    }
  }

  node *ans = nil->next;
  int cnt = 0;
  while (ans != nil) {
    if (cnt > 0)
      printf(" ");
    cnt++;
    printf("%d", ans->key);
    ans = ans->next;
  }
  printf("\\n");

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

#include <iostream>
#include <queue>
#include <string>

using namespace std;

deque<int> dll;

void printList() {
  deque<int>::iterator itr = dll.begin();
  deque<int>::iterator itrE = dll.end();
  for (; itr != itrE; itr++) {
    cout << *itr;
    if (itr != itrE - 1)
      cout << ' ';
  }
  cout << endl;
}

int main() {
  int n;
  ios::sync_with_stdio(false);
  cin >> n;

  string cmd;
  int key;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if ("insert" == cmd) {
      cin >> key;
      dll.push_front(key);
    } else if ("deleteFirst" == cmd) {
      dll.pop_front();
    } else if ("deleteLast" == cmd) {
      dll.pop_back();
    } else if ("delete" == cmd) {
      cin >> key;
      deque<int>::iterator itr = dll.begin();
      deque<int>::iterator itrE = dll.end();
      for (; itr != itrE; itr++) {
        if (key == *itr) {
          dll.erase(itr);
          break;
        }
      }
    }
  }
  printList();

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <string>

using namespace std;

deque<int> dll;

void printList() {
  deque<int>::iterator itr = dll.begin();
  deque<int>::iterator itrE = dll.end();
  for (; itr != itrE; itr++) {
    cout << *itr;
    if (itr != itrE - 1)
      cout << ' ';
  }
  cout << endl;
}

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

  string cmd;
  int key;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if ("insert" == cmd) {
      cin >> key;
      dll.push_front(key);
    } else if ("deleteFirst" == cmd) {
      dll.pop_front();
    } else if ("deleteLast" == cmd) {
      dll.pop_back();
    } else if ("delete" == cmd) {
      cin >> key;
      deque<int>::iterator itr = dll.begin();
      deque<int>::iterator itrE = dll.end();
      for (; itr != itrE; itr++) {
        if (key == *itr) {
          dll.erase(itr);
          break;
        }
      }
    }
  }
  printList();

  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, n;
  char dstr[12];
  string str;
  list<int> l;
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%s", dstr);
    str = dstr;
    if (str == "deleteFirst") {
      l.erase(l.begin());
    } else if (str == "deleteLast") {
      l.erase(--(l.end()));
    } else if (str == "delete") {
      cin >> n;
      auto it = find(l.begin(), l.end(), n);
      if (it != l.end()) {
        l.erase(it);
      }
    } else {
      cin >> n;
      l.push_front(n);
    }
  }
  cout << *(l.begin());
  for (auto it = ++l.begin(); it != l.end(); it++) {
    cout << ' ' << *it;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int N, n;
  string str;
  list<int> l;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str;
    if (str == "deleteFirst") {
      l.erase(l.begin());
    } else if (str == "deleteLast") {
      l.erase(--(l.end()));
    } else if (str == "delete") {
      cin >> n;
      auto it = find(l.begin(), l.end(), n);
      if (it != l.end()) {
        l.erase(it);
      }
    } else {
      cin >> n;
      l.push_front(n);
    }
  }
  cout << *(l.begin());
  for (auto it = ++l.begin(); it != l.end(); it++) {
    cout << ' ' << *it;
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <deque>
#include <iostream>
#include <string>

using namespace std;

void printDeque(deque<int> &d) {
  deque<int>::iterator ite = d.begin();
  while (ite != d.end()) {
    if (ite != d.begin())
      cout << " ";
    cout << *ite;
    ite++;
  }
  cout << endl;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  deque<int> d;
  while (n--) {
    string cmd;
    int val;
    cin >> cmd;
    if (cmd.compare("insert") == 0) {
      cin >> val;
      d.push_front(val);
    } else if (cmd.compare("delete") == 0) {
      cin >> val;
      deque<int>::iterator ite = d.begin();
      while (ite != d.end()) {
        if (val == *ite) {
          d.erase(ite);
          break;
        }
        ite++;
      }
    } else if (cmd.compare("deleteFirst") == 0) {
      d.pop_front();
    } else if (cmd.compare("deleteLast") == 0) {
      d.pop_back();
    }
  }
  printDeque(d);
  return 0;
}

Error: TLE

Fixed submission:

#include <deque>
#include <iostream>
#include <string>

using namespace std;

void printDeque(deque<int> &d) {
  deque<int>::iterator ite = d.begin();
  while (ite != d.end()) {
    if (ite != d.begin())
      cout << " ";
    cout << *ite;
    ite++;
  }
  cout << endl;
}

pair<string, int> split(string s) {
  int pos = s.find(" ");
  if (pos != string::npos)
    return make_pair(s.substr(0, pos), stoi(s.substr(pos + 1)));
  return make_pair(s, -1);
}

int main() {
  int n;
  cin >> n;
  cin.ignore();
  deque<int> d;
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    pair<string, int> p = split(s);
    if (p.first.compare("insert") == 0) {
      d.push_front(p.second);
    } else if (p.first.compare("delete") == 0) {
      deque<int>::iterator ite = d.begin();
      while (ite != d.end()) {
        if (p.second == *ite) {
          d.erase(ite);
          break;
        }
        ite++;
      }
    } else if (p.first.compare("deleteFirst") == 0) {
      d.pop_front();
    } else if (p.first.compare("deleteLast") == 0) {
      d.pop_back();
    }
  }
  printDeque(d);
  return 0;
}