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

#include <iostream>
#include <list>
#include <string>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x;
  string str;
  list<int> lst;
  list<int>::iterator it;
  cin >> n;
  while (n--) {
    cin >> str;
    if (str == "insert") {
      cin >> x;
      lst.push_front(x);
    } else if (str == "deleteFirst")
      lst.pop_front();
    else if (str == "deleteLast")
      lst.pop_back();

    else {
      cin >> x;
      for (it = lst.begin(); it != lst.end(); ++it) {
        if (*it == x) {
          lst.erase(it);
          break;
        }
      }
    }
  }
  for (it = lst.begin(); it != --lst.end(); ++it) {
    cout << *it << " ";
  }
  cout << *it << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <string>
using namespace std;
int main() {
  int n, x;
  string str;
  list<int> lst;
  list<int>::iterator it;
  cin >> n;
  while (n--) {
    cin >> str;
    if (str == "insert") {
      cin >> x;
      lst.push_front(x);
    } else if (str == "deleteFirst")
      lst.pop_front();
    else if (str == "deleteLast")
      lst.pop_back();

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
  list<int> l;

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char command[10];
    int key;
    cin >> command;
    if (command[0] == 'i') {
      scanf("%d", &key);
      l.push_front(key);
    } else if (command[6] == 'F') {
      l.pop_front();
    } else if (command[6] == 'L') {
      l.pop_back();
    } else if (command[0] == 'd') {
      scanf("%d", &key);
      for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
        if (*it == key) {
          l.erase(it);
          break;
        }
      }
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
  list<int> l;

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string command;
    int key;
    cin >> command;
    if (command == "insert") {
      scanf("%d", &key);
      l.push_front(key);
    } else if (command == "delete") {
      scanf("%d", &key);
      for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
        if (*it == key) {
          l.erase(it);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
  }

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

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

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

int n;
struct node {
  node *next;
  node *prev;
  long value;
};

void del(node *p) {
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
  return;
}

int main() {
  scanf("%d", &n);
  node *first = (node *)malloc(sizeof(node));
  if (first == NULL)
    exit(-1);
  node *last = (node *)malloc(sizeof(node));
  if (first == NULL)
    exit(-1);
  first->prev = NULL;
  first->next = last;
  last->prev = first;
  last->next = NULL;
  for (int i = 0; i < n; i++) {
    char cmd[20];
    scanf("%s", cmd);
    if (strcmp(cmd, "insert") == 0) {
      long t;
      scanf("%ld", &t);
      node *p = (node *)malloc(sizeof(node));
      if (p == NULL)
        exit(-1);
      p->prev = first;
      p->next = first->next;
      p->value = t;
      first->next->prev = p;
      first->next = p;
    } else if (strcmp(cmd, "delete") == 0) {
      long t;
      scanf("%ld", &t);
      node *now = first->next;
      while (now->value != t && now != last)
        now = now->next;
      if (now != last)
        del(now);
    } else if (strcmp(cmd, "deleteFirst") == 0) {
      del(first->next);
    } else if (strcmp(cmd, "deleteLast") == 0) {
      del(last->prev);
    }
  }
  node *now = first;
  while (now->next != last) {
    printf("%ld", now->next->value);
    now = now->next;
    if (now->next != last)
      printf(" ");
    else
      printf("\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

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

int n;
struct node {
  node *next;
  node *prev;
  int value;
};

void del(node *p) {
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
  return;
}

int main() {
  scanf("%d", &n);
  node *first = (node *)malloc(sizeof(node));
  if (first == NULL)
    exit(-1);
  node *last = (node *)malloc(sizeof(node));
  if (first == NULL)
    exit(-1);
  first->prev = NULL;
  first->next = last;
  last->prev = first;
  last->next = NULL;
  for (int i = 0; i < n; i++) {
    char cmd[20];
    scanf("%s", cmd);
    if (strcmp(cmd, "insert") == 0) {
      int t;
      scanf("%d", &t);
      node *p = (node *)malloc(sizeof(node));
      if (p == NULL)
        exit(-1);
      p->prev = first;
      p->next = first->next;
      p->value = t;
      first->next->prev = p;
      first->next = p;
    } else if (strcmp(cmd, "delete") == 0) {
      int t;
      scanf("%d", &t);
      node *now = first->next;
      while (now->value != t)
        now = now->next;
      del(now);
    } else if (strcmp(cmd, "deleteFirst") == 0) {
      del(first->next);
    } else if (strcmp(cmd, "deleteLast") == 0) {
      del(last->prev);
    }
  }
  node *now = first;
  while (now->next != last) {
    printf("%d", now->next->value);
    now = now->next;
    if (now->next != last)
      printf(" ");
    else
      printf("\\n");
  }
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

class bilist {
  long a[2000001];
  long L, R;

public:
  bilist() { L = 0, R = -1; }
  long size() { return R - L + 1; }
  void insert(long x) { a[++R] = x; }
  void deleteFirst() {
    while (L < R && a[R] == -1)
      --R;
    a[R--] = -1;
    while (L < R && a[R] == -1)
      --R;
  }
  void deleteLast() {
    while (L < R && a[L] == -1)
      ++L;
    a[L++] = -1;
    while (L < R && a[L] == -1)
      ++L;
  }
  void del(long x) {
    long ite = R;
    for (; ite >= L; --ite) {
      if (a[ite] == x) {
        a[ite] = -1;
        return;
      }
    }
    if (ite < L)
      return;
  }
  void print() {
    bool Top = true;
    for (long i = R; i >= L; --i) {
      if (a[i] == -1)
        continue;
      if (!Top)
        cout << ' ';
      Top = false;
      cout << a[i];
    }
    cout << '\\n';
  }
};

bilist blist;
int main() {
  long n;
  scanf("%ld", &n);
  while (n--) {
    char tmp[20];
    scanf("%s", &tmp);
    string a;
    a = tmp;
    if (a == "insert" || a == "delete") {
      long b;
      scanf("%ld", &b);
      if (a == "insert") {
        blist.insert(b);
      } else {
        blist.del(b);
      }
    } else if (a == "deleteFirst") {
      blist.deleteFirst();
    } else if (a == "deleteLast") {
      blist.deleteLast();
    }
    // blist.print();
  }
  blist.print();
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

class bilist {
  long a[2000001];
  long L, R;

public:
  bilist() { L = 0, R = -1; }
  long size() { return R - L + 1; }
  void insert(long x) { a[++R] = x; }
  void deleteFirst() {
    while (L < R && a[R] == -1)
      --R;
    a[R--] = -1;
    while (L < R && a[R] == -1)
      --R;
  }
  void deleteLast() {
    while (L < R && a[L] == -1)
      ++L;
    a[L++] = -1;
    while (L < R && a[L] == -1)
      ++L;
  }
  void del(long x) {
    long ite = R;
    for (; ite >= L; --ite) {
      if (a[ite] == x) {
        a[ite] = -1;
        return;
      }
    }
    if (ite < L)
      return;
  }
  void print() {
    bool Top = true;
    for (long i = R; i >= L; --i) {
      if (a[i] == -1)
        continue;
      if (!Top)
        cout << ' ';
      Top = false;
      cout << a[i];
    }
    cout << '\\n';
  }
};

bilist blist;
int main() {
  long n;
  cin >> n;
  while (n--) {
    string a;
    cin >> a;
    if (a == "insert" || a == "delete") {
      long b;
      cin >> b;
      if (a == "insert") {
        blist.insert(b);
      } else {
        blist.del(b);
      }
    } else if (a == "deleteFirst") {
      blist.deleteFirst();
    } else if (a == "deleteLast") {
      blist.deleteLast();
    }
    // blist.print();
  }
  blist.print();
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

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

  int n;
  cin >> n;

  list<int> l;
  for (int i = 0; i < n; i++) {
    string command;
    cin >> command;
    if (command == "insert") {
      int x;
      cin >> x;
      l.push_front(x);
    } else if (command == "delete") {
      int x;
      cin >> x;
      for (list<int>::iterator i = l.begin(); i != l.end(); i++) {
        if (*i == x) {
          l.erase(i);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
  }

  list<int>::iterator i;
  for (i = l.begin(); i != --l.end(); i++) {
    cout << *i << " ";
  }
  cout << *i << 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 command;
    cin >> command;
    if (command == "insert") {
      int x;
      cin >> x;
      l.push_front(x);
    } else if (command == "delete") {
      int x;
      cin >> x;
      for (list<int>::iterator i = l.begin(); i != l.end(); i++) {
        if (*i == x) {
          l.erase(i);
          break;
        }
      }
    } else if (command == "deleteFirst") {
      l.pop_front();
    } else if (command == "deleteLast") {
      l.pop_back();
    }
  }

  list<int>::iterator i;
  for (i = l.begin(); i != --l.end(); i++) {
    cout << *i << " ";
  }
  cout << *i << endl;

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i, x;
  string s;
  deque<int> intlist;
  cin >> n;

  for (i = 0; i <= n - 1; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> x;
      intlist.push_front(x);
    } else if (s == "delete") {
      cin >> x;
      deque<int>::iterator it = intlist.begin();
      while (1) {
        if (*it == x) {
          it = intlist.erase(it);
          break;
        } else if (it == intlist.end()) {
          break;
        }
        it++;
      }
    } else if (s == "deleteFirst") {
      intlist.pop_front();
    } else if (s == "deleteLast") {
      intlist.pop_back();
    }
  }

  deque<int>::iterator it = intlist.begin();
  cout << *it;
  it++;
  while (1) {
    if (it == intlist.end()) {
      cout << "\\n";
      break;
    }
    cout << " " << *it;
    it++;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i, x;
  string s;
  deque<int> intlist;
  cin >> n;

  for (i = 0; i <= n - 1; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> x;
      intlist.push_front(x);
    } else if (s == "delete") {
      cin >> x;
      deque<int>::iterator it = intlist.begin();
      while (1) {
        if (*it == x) {
          it = intlist.erase(it);
          break;
        } else if (it == intlist.end()) {
          break;
        }
        it++;
      }
    } else if (s == "deleteFirst") {
      intlist.pop_front();
    } else if (s == "deleteLast") {
      intlist.pop_back();
    }
  }

  deque<int>::iterator it = intlist.begin();
  cout << *it;
  it++;
  while (1) {
    if (it == intlist.end()) {
      cout << "\\n";
      break;
    }
    cout << " " << *it;
    it++;
  }

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

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

struct DLL {
  ll x;
  DLL *next;
  DLL *prev;
};

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  DLL *head;
  head = (DLL *)malloc(sizeof(DLL));
  head->x = -1;
  head->next = head;
  head->prev = head;
  for (int i = 0; i < n; i++) {
    string comm;
    ll v;
    cin >> comm;
    if (comm == "insert") {
      cin >> v;
      DLL *x;
      x = (DLL *)malloc(sizeof(DLL));
      x->x = v;
      x->next = head->next;
      head->next->prev = x;
      head->next = x;
      x->prev = head;
    }
    if (comm == "delete") {
      cin >> v;
      DLL *key;
      key = head->next;
      while (1) {
        if (key == head)
          break;
        if (key->x == v) {
          key->prev->next = key->next;
          key->next->prev = key->prev;
          free(key);
          break;
        }
        key = key->next;
      }
    }
    if (comm == "deleteFirst") {
      DLL *key = head->next;
      key->prev->next = key->next;
      key->next->prev = key->prev;
      free(key);
    }
    if (comm == "deleteLast") {
      DLL *key = head->prev;
      key->prev->next = key->next;
      key->next->prev = key->prev;
      free(key);
    }
  }

  DLL *a;
  a = head->next;
  while (a != head) {
    if (a->next == head)
      cout << a->x << endl;
    else
      cout << a->x << " ";
    a = a->next;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

struct DLL {
  ll x;
  DLL *next;
  DLL *prev;
};

int main(void) {
  int n;
  cin >> n;
  DLL *head;
  head = (DLL *)malloc(sizeof(DLL));
  head->x = -1;
  head->next = head;
  head->prev = head;
  for (int i = 0; i < n; i++) {
    string comm;
    ll v;
    cin >> comm;
    if (comm == "insert") {
      cin >> v;
      DLL *x;
      x = (DLL *)malloc(sizeof(DLL));
      x->x = v;
      x->next = head->next;
      head->next->prev = x;
      head->next = x;
      x->prev = head;
    }
    if (comm == "delete") {
      cin >> v;
      DLL *key;
      key = head->next;
      while (1) {
        if (key == head)
          break;
        if (key->x == v) {
          key->prev->next = key->next;
          key->next->prev = key->prev;
          free(key);
          break;
        }
        key = key->next;
      }
    }
    if (comm == "deleteFirst") {
      DLL *key = head->next;
      key->prev->next = key->next;
      key->next->prev = key->prev;
      free(key);
    }
    if (comm == "deleteLast") {
      DLL *key = head->prev;
      key->prev->next = key->next;
      key->next->prev = key->prev;
      free(key);
    }
  }

  DLL *a;
  a = head->next;
  while (a != head) {
    if (a->next == head)
      cout << a->x << endl;
    else
      cout << a->x << " ";
    a = a->next;
  }

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

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

using namespace std;
list<int> lst;

int main() {
  int dataset;
  scanf("%d", &dataset);
  for (int i = 0; i < dataset; i++) {
    char order[20];
    scanf("%s", order);
    if (order[0] == 'i') {
      int a;
      scanf("%d", &a);
      lst.push_front(a);
    } else if (order[6] == 'F') {
      lst.pop_front();
    } else if (order[6] == 'L') {
      lst.pop_back();
    } else {
      int order;
      cin >> order;
      auto itr = lst.begin();
      int size = lst.size();
      for (int i = 0; i < size; i++) {
        if (*itr == order) {
          lst.erase(itr);
          break;
        }
        itr++;
      }
    }
  }
  for (auto itr = lst.begin(); itr != lst.end(); itr++) {
    if (itr != lst.begin()) {
      printf(" ");
    }
    printf("%d", *itr);
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
list<int> lst;

int main() {
  int dataset;
  scanf("%d", &dataset);
  for (int i = 0; i < dataset; i++) {
    string order;
    cin >> order;
    if (order[0] == 'i') {
      int a;
      scanf("%d", &a);
      lst.push_front(a);
    } else if (order[6] == 'F') {
      lst.pop_front();
    } else if (order[6] == 'L') {
      lst.pop_back();
    } else {
      int order;
      cin >> order;
      auto itr = lst.begin();
      int size = lst.size();
      for (int i = 0; i < size; i++) {
        if (*itr == order) {
          lst.erase(itr);
          break;
        }
        itr++;
      }
    }
  }
  for (auto itr = lst.begin(); itr != lst.end(); itr++) {
    if (itr != lst.begin()) {
      printf(" ");
    }
    printf("%d", *itr);
  }
  printf("\\n");
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

class List {
  Node *nil;
  Node *searchNode(int x) {
    Node *p = nil->next;
    while (p != nil && p->data != x) {
      p = p->next;
    }
    return p;
  }
  void deleteNode(Node *node) {
    if (node == nil)
      return;
    node->prev->next = node->next;
    node->next->prev = node->prev;
    delete (node);
  }

public:
  List() {
    nil = new Node();
    nil->next = nil;
    nil->prev = nil;
  }
  void insertFirst(int x) {
    Node *node = new Node();
    node->data = x;
    node->next = nil->next;
    node->prev = nil;

    nil->next->prev = node;
    nil->next = node;
  }
  void deleteData(int x) { deleteNode(searchNode(x)); }
  void deleteFirst() { deleteNode(nil->next); }
  void deleteLast() { deleteNode(nil->prev); }
  void print() {
    Node *p = nil->next;
    while (p != nil) {
      if (p != nil->next)
        cout << " ";
      cout << p->data;
      p = p->next;
    }
    cout << endl;
  }
};

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

  List l;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int num;
    string command;
    cin >> command;
    if (command == "insert") {
      cin >> num;
      l.insertFirst(num);
    } else if (command == "delete") {
      cin >> num;
      l.deleteData(num);
    } else if (command == "deleteFirst") {
      l.deleteFirst();
    } else if (command == "deleteLast") {
      l.deleteLast();
    }
  }
  l.print();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

class List {
  Node *nil;
  Node *searchNode(int x) {
    Node *p = nil->next;
    while (p != nil && p->data != x) {
      p = p->next;
    }
    return p;
  }
  void deleteNode(Node *node) {
    if (node == nil)
      return;
    node->prev->next = node->next;
    node->next->prev = node->prev;
    delete (node);
  }

public:
  List() {
    nil = new Node();
    nil->next = nil;
    nil->prev = nil;
  }
  void insertFirst(int x) {
    Node *node = new Node();
    node->data = x;
    node->next = nil->next;
    node->prev = nil;

    nil->next->prev = node;
    nil->next = node;
  }
  void deleteData(int x) { deleteNode(searchNode(x)); }
  void deleteFirst() { deleteNode(nil->next); }
  void deleteLast() { deleteNode(nil->prev); }
  void print() {
    Node *p = nil->next;
    while (p != nil) {
      if (p != nil->next)
        cout << " ";
      cout << p->data;
      p = p->next;
    }
    cout << endl;
  }
};

int main() {
  List l;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int num;
    string command;
    cin >> command;
    if (command == "insert") {
      cin >> num;
      l.insertFirst(num);
    } else if (command == "delete") {
      cin >> num;
      l.deleteData(num);
    } else if (command == "deleteFirst") {
      l.deleteFirst();
    } else if (command == "deleteLast") {
      l.deleteLast();
    }
  }
  l.print();
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <sstream>
using namespace std;
/*以下の命令を受けつける双方向連結リストを実装してください。
insert x: 連結リストの先頭にキー x を持つ要素を継ぎ足す。
delete x: キー x
を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
deleteFirst: リストの先頭の要素を削除する。
deleteLast: リストの末尾の要素を削除する。*/
int main() {
  list<int> l;
  string command;
  getline(cin, command);
  while (getline(cin, command)) {
    if (command == "deleteFirst") {
      l.pop_front();
      continue;
    } else if (command == "deleteLast") {
      l.pop_back();
      continue;
    }
    auto pos = command.find(" ");
    int value = stoi(command.substr(pos + 1));
    if (command.find("insert") != string::npos) {
      l.push_front(value);
    } else if (command.find("delete") != string::npos) {
      auto result = find(l.begin(), l.end(), value);
      if (l.end() != result) {
        l.erase(result);
      }
    }
  }
  for (auto itr = l.begin(), end = l.end(); itr != end; itr++) {
    cout << *itr << ((next(itr) != end) ? " " : "");
  }
  cout << endl;
}


Error: -6
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi


Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <sstream>
using namespace std;
/*以下の命令を受けつける双方向連結リストを実装してください。
insert x: 連結リストの先頭にキー x を持つ要素を継ぎ足す。
delete x: キー x
を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
deleteFirst: リストの先頭の要素を削除する。
deleteLast: リストの末尾の要素を削除する。*/
int main() {
  list<int> l;
  int n;
  cin >> n;
  string command;
  while (getline(cin, command)) {
    if (command.find("deleteFirst") != string::npos) {
      l.pop_front();
      continue;
    } else if (command.find("deleteLast") != string::npos) {
      l.pop_back();
      continue;
    }
    auto pos = command.find(" ");
    int value = stoi(command.substr(pos + 1));
    if (command.find("insert") != string::npos) {
      l.push_front(value);
    } else if (command.find("delete") != string::npos) {
      auto result = find(l.begin(), l.end(), value);
      if (l.end() != result) {
        l.erase(result);
      }
    }
  }
  for (auto itr = l.begin(), end = l.end(); itr != end; itr++) {
    cout << *itr << ((next(itr) != end) ? " " : "");
  }
  cout << endl;
}