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;
  //  cin >> n;
  scanf("%d", &n);
  list<int> l;
  for (int i = 0; i < n; i++) {
    string command;
    cin >> command;
    if (command == "insert") {
      int x;
      //      cin >> x;
      scanf("%d", &x);
      l.push_front(x);
    } else if (command == "deleteFirst")
      l.pop_front();
    else if (command == "deleteLast")
      l.pop_back();
    else if (command == "delete") {
      int x;
      //      cin >> x;
      scanf("%d", &x);
      for (auto it = l.begin(); it != l.end(); it++)
        if (*it == x) {
          l.erase(it);
          break;
        }
    }
  }
  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 <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 == "deleteFirst")
      l.pop_front();
    else if (command == "deleteLast")
      l.pop_back();
    else if (command == "delete") {
      int x;
      cin >> x;
      for (auto it = l.begin(); it != l.end(); it++)
        if (*it == x) {
          l.erase(it);
          break;
        }
    }
  }
  int first = 1;
  for (auto it = l.begin(); it != l.end(); it++) {
    if (!first)
      cout << " ";
    cout << *it;
    first = 0;
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <list>

using namespace std;

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

  string cmd;
  int i, arg;
  for (i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> arg;
      list.push_front(arg);
    } else if (cmd == "delete") {
      cin >> arg;
      int pos = 0;
      for (int tmp : list) {
        if (tmp == arg)
          break;
        pos++;
      }
      if (pos != static_cast<int>(list.size()))
        list.erase(next(list.begin(), pos));
    } else if (cmd == "deleteFirst") {
      list.pop_front();
    } else if (cmd == "deleteLast") {
      list.pop_back();
    }
  }

  int size = static_cast<int>(list.size());
  if (size > 0) {
    cout << list.front();
    list.pop_front();
    for (i = 1; i < size; i++) {
      cout << ' ' << list.front();
      list.pop_front();
    }
  }
  cout << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <list>

using namespace std;

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

  string cmd;
  int i, arg;
  for (i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> arg;
      list.push_front(arg);
    } else if (cmd == "delete") {
      cin >> arg;
      int pos = 0;
      for (int tmp : list) {
        if (tmp == arg)
          break;
        pos++;
      }
      list.erase(next(list.begin(), pos));
    } else if (cmd == "deleteFirst") {
      list.pop_front();
    } else if (cmd == "deleteLast") {
      list.pop_back();
    }
  }

  int size = static_cast<int>(list.size());
  if (size > 0) {
    cout << list.front();
    list.pop_front();
    for (i = 1; i < size; i++) {
      cout << ' ' << list.front();
      list.pop_front();
    }
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

const char *INSERT = "insert";
const char *DELETE = "delete";
const char *DELETE_FIRST = "deleteFirst";
const char *DELETE_LAST = "deleteLast";

int main(void) {

  int n;
  cin >> n;

  list<int> nodes;
  char command[15];
  for (int i = 0; i < n; ++i) {
    //        cin >> command;       // NG?
    scanf("%s", command); // OK?
                          //        printf("[echo] %s\\n", command);
                          //        cout << "[echo] " << command << endl;
    if (strncmp(command, INSERT, 6) == 0) {
      //            printf("[command] Insert\\n");
      int x;
      cin >> x;
      nodes.push_front(x);
    } else if (strncmp(command, DELETE_FIRST, 11) == 0) {
      //            printf("[command] Delete First\\n");
      nodes.pop_front();
    } else if (strncmp(command, DELETE_LAST, 10) == 0) {
      //            printf("[command] Delete Last\\n");
      nodes.pop_back();
    } else if (strncmp(command, DELETE, 6) == 0) {
      //            printf("[command] Delete\\n");
      int x;
      cin >> x;
      list<int>::iterator it;
      for (it = nodes.begin(); it != nodes.end(); ++it) {
        if (*it == x) {
          break;
        }
      }
      if (it != nodes.end()) {
        nodes.erase(it);
      }
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

const string INSERT = "insert";
const string DELETE = "delete";
const string DELETE_FIRST = "deleteFirst";
const string DELETE_LAST = "deleteLast";

int main(void) {

  int n;
  cin >> n;

  list<int> nodes;
  for (int i = 0; i < n; ++i) {
    string command;
    cin >> command;
    if (command == INSERT) {
      int x;
      cin >> x;
      nodes.push_front(x);
    } else if (command == DELETE) {
      int x;
      cin >> x;
      list<int>::iterator it;
      for (it = nodes.begin(); it != nodes.end(); ++it) {
        if (*it == x) {
          break;
        }
      }
      if (it != nodes.end()) {
        nodes.erase(it);
      }
    } else if (command == DELETE_FIRST) {
      nodes.pop_front();
    } else if (command == DELETE_LAST) {
      nodes.pop_back();
    }
  }

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

  return 0;
}
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 init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key) {
  Node *p = (Node *)malloc(sizeof(Node));
  p->key = key;

  p->next = nil->next;
  nil->next->prev = p;
  nil->next = p;
  p->prev = nil;
}

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

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

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

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

void deleteKey(int key) { deleteNode(listSearch(key)); }

int main() {
  ios::sync_with_stdio(false);
  int n, key;
  string s;
  Node *cur;

  cin >> n;

  init();

  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> key;
      insert(key);
    } else if (s == "delete") {
      cin >> key;
      deleteKey(key);
    } else if (s == "deleteFirst") {
      deleteFirst();
    } else if (s == "deleteLast") {
      deleteLast();
    }
  }

  int j = 0;
  cur = nil->next;

  while (1) {
    if (cur == nil) {
      break;
    }

    if (j++ > 0) {
      cout << " ";
    }

    cout << cur->key;
    cur = cur->next;
  }

  cout << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

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

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

Node *nil;

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

void insert(int key) {
  Node *p = (Node *)malloc(sizeof(Node));
  p->key = key;

  p->next = nil->next;
  nil->next->prev = p;
  nil->next = p;
  p->prev = nil;
}

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

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

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

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

void deleteKey(int key) { deleteNode(listSearch(key)); }

int main() {
  int n, key;
  string s;
  Node *cur;

  scanf("%d", &n);

  init();

  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      scanf("%d", &key);
      insert(key);
    } else if (s == "delete") {
      scanf("%d", &key);
      deleteKey(key);
    } else if (s == "deleteFirst") {
      deleteFirst();
    } else if (s == "deleteLast") {
      deleteLast();
    }
  }

  int j = 0;
  cur = nil->next;

  while (1) {
    if (cur == nil) {
      break;
    }

    if (j++ > 0) {
      printf(" ");
    }

    printf("%d", cur->key);
    cur = cur->next;
  }

  printf("\\n");

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VC vector<char>
#define VVI vector<vector<int>>
#define rep(i, n) for (int i = 0; i < n; i++)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c.begin(), c.end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main() {
  list<int> data;
  list<int>::iterator itr, l;
  int q;
  cin >> q;
  string cd;
  int key;
  rep(i, q) {
    cin >> cd;
    if (cd == "insert") {
      cin >> key;
      data.push_front(key);
    } else if (cd == "delete") {
      cin >> key;
      for (itr = data.begin(), l = data.end(); itr != l; ++itr) {
        if (*itr == key) {
          data.erase(itr);
          break;
        }
      }
    } else if (cd == "deleteFirst") {
      data.pop_front();
    } else {
      data.pop_back();
    }
  }
  for (itr = data.begin(), l = --data.end(); itr != l; ++itr) {
    cout << *itr << " ";
  }
  cout << *itr << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VC vector<char>
#define VVI vector<vector<int>>
#define rep(i, n) for (int i = 0; i < n; i++)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c.begin(), c.end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main() {
  VI list;
  int q;
  cin >> q;
  rep(i, q) {
    string cd;
    cin >> cd;
    int key;
    if (cd == "insert") {
      cin >> key;
      list.insert(list.begin(), key);
    } else if (cd == "delete") {
      cin >> key;
      rep(i, list.size()) {
        if (list[i] == key) {
          list.erase(list.begin() + i);
          break;
        }
      }
    } else if (cd == "deleteFirst") {
      list.erase(list.begin());
    } else if (cd == "deleteLast") {
      list.erase(list.begin() + list.size() - 1);
    } else {
      cout << "Error" << endl;
      i--;
    }
  }
  rep(i, list.size()) {
    cout << list[i];
    if (i == list.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

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

  bool first = true;
  for (list<int>::iterator s = a.begin(); s != a.end(); s++) {
    if (first)
      first = false;
    else {
      printf(" ");
    } // cout << *s << " ";
    printf("%d", *s);
  }
  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

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

  list<int>::iterator s = a.begin();
  for (int i = 0; i < a.size() - 1; i++) {
    printf("%d ", *s);
    // cout << *s << " ";
    s++;
  }
  cout << *s << endl;

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

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

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

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

  int n;
  string st;
  int x;
  cin >> n;
  list<int> L;
  list<int>::iterator it, endit;

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

    if (st == "insert") {
      cin >> x;
      L.push_front(x);
    }

    else if (st == "delete") {
      cin >> x;
      for (it = L.begin(), endit = L.end(); it != endit; ++it) {
        if (*it == x) {
          L.erase(it);
          break;
        }
      }
    }

    else if (st == "deleteFirst") {
      L.pop_front();
    }

    else { // deleteLast
      L.pop_back();
    }
  }

  for (it = L.begin(), endit = --L.end(); it != endit; ++it) {
    cout << *it << ' ';
  }
  cout << *it << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

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

int main() {
  int n;
  string st;
  int x;
  cin >> n;
  list<int> L;
  list<int>::iterator it, endit;

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

    if (st == "insert") {
      cin >> x;
      L.push_front(x);
    }

    else if (st == "delete") {
      cin >> x;
      for (it = L.begin(), endit = L.end(); it != endit; ++it) {
        if (*it == x) {
          L.erase(it);
          break;
        }
      }
    }

    else if (st == "deleteFirst") {
      L.pop_front();
    }

    else { // deleteLast
      L.pop_back();
    }
  }

  for (it = L.begin(), endit = --L.end(); it != endit; ++it) {
    cout << *it << ' ';
  }
  cout << *it << endl;

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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

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

Node *nil;

Node *search(int k) {
  Node *x = nil->next;

  while (x != nil && x->key != k)
    x = x->next;

  return x;
}

void insert(int k) {
  Node *x = (Node *)malloc(sizeof(Node));

  x->key = k;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

void deleteNode(Node *x) {
  if (x == nil)
    return;
  x->prev->next = x->next;
  x->next->prev = x->prev;

  free(x);
}

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

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

int main() {

  int n, k;
  char command[20];

  nil = (Node *)malloc(sizeof(Node));
  nil->prev = nil;
  nil->next = nil;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", command);
    if (strcmp(command, "insert") == 0) {
      scanf("%d", &k);
      insert(k);
    } else if (strcmp(command, "delete") == 0) {
      scanf("%d", &k);
      deleteNode(search(k));
    } else if (strcmp(command, "deleteFirst") == 0) {
      deleteFirst();
    } else if (strcmp(command, "deleteLast") == 0) {
      deleteLast();
    }
  }

  k = 0;
  Node *x = nil->next;
  while (x != nil) {
    printf((k ? " " : ""));
    printf("%d", x->key);
    k++;
    x = x->next;
  }
  printf("\\n");

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

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

Node *nil;

Node *search(int k) {
  Node *x = nil->next;

  while (x != nil && x->key != k)
    x = x->next;

  return x;
}

void insert(int k) {
  Node *x = (Node *)malloc(sizeof(Node));

  x->key = k;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

void deleteNode(Node *x) {
  x->prev->next = x->next;
  x->next->prev = x->prev;

  free(x);
}

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

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

int main() {

  int n, k;
  char command[20];

  nil = (Node *)malloc(sizeof(Node));
  nil->prev = nil;
  nil->next = nil;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", command);
    if (strcmp(command, "insert") == 0) {
      scanf("%d", &k);
      insert(k);
    } else if (strcmp(command, "delete") == 0) {
      scanf("%d", &k);
      deleteNode(search(k));
    } else if (strcmp(command, "deleteFirst") == 0) {
      deleteFirst();
    } else if (strcmp(command, "deleteLast") == 0) {
      deleteLast();
    }
  }

  k = 0;
  Node *x = nil->next;
  while (x != nil) {
    printf((k ? " " : ""));
    printf("%d", x->key);
    k++;
    x = x->next;
  }
  printf("\\n");

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

vector<int> igets(int N) {
  vector<int> A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  list<int> DATA;
  for (int i = 0; i < N; i++) {
    string commnad;
    cin >> commnad;
    int num;
    if (commnad == "insert" || commnad == "delete")
      cin >> num;
    if (commnad == "insert") {
      DATA.push_front(num);
    } else if (commnad == "delete") {
      for (list<int>::iterator ip = DATA.begin(); ip != DATA.end(); ip++) {
        if (*ip == num) {
          DATA.erase(ip);
          break;
        }
      }
    } else if (commnad == "deleteFirst") {
      DATA.pop_front();
    } else {
      DATA.pop_back();
    }
  }
  bool a = 1;
  for (list<int>::iterator ip = DATA.begin(); ip != DATA.end(); ip++) {
    if (a) {
      cout << *ip;
      a = 0;
    } else
      cout << " " << *ip;
  }
  cout << endl;
}


Error: -6
free(): invalid size


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

vector<int> igets(int N) {
  vector<int> A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  list<int> DATA;
  for (int i = 0; i < N; i++) {
    char commnad[20];
    scanf("%s", commnad);
    int num;
    if (commnad == "insert" || commnad == "delete")
      scanf("%d", &num);
    if (commnad == "insert") {
      DATA.push_front(num);
    } else if (commnad == "delete") {
      for (list<int>::iterator ip = DATA.begin(); ip != DATA.end(); ip++) {
        if (*ip == num) {
          DATA.erase(ip);
          break;
        }
      }
    } else if (commnad == "deleteFirst") {
      DATA.pop_front();
    } else {
      DATA.pop_back();
    }
  }
  bool a = 1;
  for (list<int>::iterator ip = DATA.begin(); ip != DATA.end(); ip++) {
    if (a) {
      cout << *ip;
      a = 0;
    } else
      cout << " " << *ip;
  }
  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <string>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  bool flag = false;
  int n, num;
  string s;
  list<int> intlist;
  list<int>::iterator it;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "insert") {
      cin >> num;
      intlist.push_front(num);
    } else if (s == "delete") {
      cin >> num;
      for (it = intlist.begin(); it != intlist.end(); ++it) {
        if (*it == num) {
          intlist.erase(it);
          break;
        }
      }
    } else if (s == "deleteFirst") {
      intlist.pop_front();
    } else if (s == "deleteLast") {
      intlist.pop_back();
    }
  }
  for (it = intlist.begin(); it != intlist.end(); ++it) {
    if (flag == false) {
      cout << *it;
      flag = true;
    } else
      cout << " " << *it;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<vector<bool>> matb;
typedef vector<string> vst;
typedef pair<lli, lli> pll;
typedef pair<double, double> pdd;

list<lli> l;
lli n;

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