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

#include <cstdio>
#include <cstring>
using std::size_t;

struct Node {
  int key;
  Node *prev, *next;
  Node() : Node(0) {}
  Node(int k) : key(k), prev(nullptr), next(nullptr) {}
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
class List {
private:
  Node *nil;

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

  const Node *const begin() const { return (nil->next); }
  const Node *const end() const { return (nil); }

  const Node *const search(int k) const;
  void push_front(int k);
  void erase(const Node *const u);
  void erase_key(int k);
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void List::push_front(int k) {
  Node *u = new Node(k);
  nil->next->prev = u;
  u->next = nil->next;
  nil->next = u;
  u->prev = nil;
}

const Node *const List::search(int k) const {
  Node *i = nil->next;
  while (i != nil && i->key != k)
    i = i->next;
  return (i);
}

void List::erase(const Node *const u) {
  if (u == nil)
    return;
  u->next->prev = u->prev;
  u->prev->next = u->next;
  delete u;
}

void List::erase_key(int k) { erase(search(k)); }
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

static List ls;

int main() {
  int N;
  char s[32];
  scanf("%d", &N);

  while (N--) {
    scanf("%s", s);
    if (strlen(s) == 6) {
      int n;
      scanf("%d", &n);
      if (*s == 'd')
        ls.erase_key(n);
      else
        ls.push_front(n);
    } else {
      if (s[6] == 'F')
        ls.erase(ls.begin());
      else
        ls.erase(ls.end()->prev);
    }
  }

  bool nf = false;
  for (auto i = ls.begin(); i != ls.end(); i = i->next) {
    if (nf)
      printf(" ");
    else
      nf = true;
    printf("%d", i->key);
  }
  printf("\\n");
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <list>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, f, n) for (int i = (f); i <= (n); ++i)
#define outl(x) cout << (x) << '\\n'

#define same(s, w) (strcmp(s, w) == 0)

int kfind(list<int> &ls, int k) {
  auto it = ls.begin();
  for (int i = 0; i < ls.size(); ++i) {
    if (*it == k)
      return (i);
    ++it;
  }
  return (-1);
}

int main() {
  int N;
  char com[32];
  list<int> ls;

  scanf("%d", &N);
  while (N--) {
    scanf("%s", com);
    if (strlen(com) == 6) {
      int n;
      scanf("%d", &n);

      if (com[0] == 'd') {
        int p = kfind(ls, n);
        if (p != -1)
          ls.erase(next(ls.begin(), p));

      } else {
        ls.push_front(n);
      }
    } else {
      ls.erase((com[6] == 'F') ? ls.begin() : next(ls.end(), -1));
    }
  }

  for (int i = 0; i < ls.size(); ++i) {
    printf("%d%c", *next(ls.begin(), i), i + 1 < ls.size() ? ' ' : '\\n');
  }
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

using namespace std;

int main() {
  list<int> li, tmp;
  int n, x;
  string com;

  scanf("%d", &n);
  REP(i, n) {
    cin >> com;

    if (com == "deleteFirst") {
      li.pop_front();
    } else if (com == "deleteLast") {
      li.pop_back();
    } else if (com == "delete") {
      cin >> x;
      int k = 0;
      for (auto itr = li.begin(); itr != li.end();) {
        if (*itr == x && k == 0) {
          itr = li.erase(itr);
          k = 1;
        } else {
          ++itr;
        }
      }
    } else if (com == "insert") {
      cin >> x;
      li.push_front(x);
    }
  }
  int l = li.size();
  REP(i, l - 1) {
    cout << li.front() << " ";
    li.pop_front();
  }
  cout << li.front() << endl;

  return 0;
}


Error: WA

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

using namespace std;

int main() {
  list<int> li, tmp;
  int n, x;
  string com;

  scanf("%d", &n);
  REP(i, n) {
    cin >> com;

    if (com == "deleteFirst") {
      li.pop_front();
    } else if (com == "deleteLast") {
      li.pop_back();
    } else if (com == "delete") {
      cin >> x;
      int k = 0;
      tmp.clear();
      REP(j, li.size()) {
        if (k == 1 || li.front() != x) {
          tmp.push_back(li.front());
        } else {
          k++;
        }
        li.pop_front();
      }
      li = tmp;
    } else if (com == "insert") {
      cin >> x;
      li.push_front(x);
    }
  }
  int l = li.size();
  REP(i, l - 1) {
    cout << li.front() << " ";
    li.pop_front();
  }
  cout << li.front() << endl;

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

#include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
using namespace std;

int main() {
  int i, j, n;
  long long int x;
  list<long long int> l;
  list<long long int>::iterator itl;
  // ifstream fin("ALDS1_3_C-in10.txt");
  // if (!fin) {
  //	cout << "failed to open the file\\n";
  //	return 1;
  // }
  // ofstream fout("out.txt");
  cin >> n;
  for (i = 0; i < n; i++) {
    char com[15] = {};
    cin >> com;
    if (com[0] == 'i') {
      cin >> x;
      l.push_front(x);
    } else if (com[6] == 'F')
      l.pop_front();
    else if (com[6] == 'L')
      l.pop_back();
    else if (com[0] == 'd') {
      cin >> x;
      for (itl = l.begin(); itl != l.end(); itl++) {
        if (*itl == x) {
          l.erase(itl);
          break;
        }
      }
    }
  }
  for (itl = l.begin(); itl != l.end(); itl++) {
    if (itl != l.begin())
      cout << " ";
    cout << *itl;
  }
  cout << endl;
  // fin.close();
  // fout.close();
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int i, j, n;
  long long int x;
  list<long long int> l;
  list<long long int>::iterator itl;
  cin >> n;
  for (i = 0; i < n; i++) {
    char com[15] = {};
    cin >> com;
    if (com[0] == 'i') {
      cin >> x;
      l.push_front(x);
    } else if (com[6] == 'F')
      l.pop_front();
    else if (com[6] == 'L')
      l.pop_back();
    else if (com[0] == 'd') {
      cin >> x;
      itl = find(l.begin(), l.end(), x);
      l.erase(itl);
    }
  }
  itl = l.begin();
  while (itl != l.end()) {
    cout << *itl;
    itl++;
    if (itl != l.end())
      cout << " ";
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

class Node {
public:
  Node *prev;
  Node *next;
  int data;
  Node() {
    prev = 0;
    next = 0;
    data = 0;
  }
};

class List {
private:
  Node head;

public:
  List() {
    head.next = &head;
    head.prev = &head;
  }
  int insert(int a) {
    Node *p = new Node();

    if (p == 0) {
      return -1;
    }

    Node *q = &head;
    Node *r = head.next;

    p->prev = q;
    p->next = r;
    p->data = a;

    q->next = p;
    r->prev = p;

    return 0;
  }

  int del(int a) {
    Node *p;

    for (p = head.next; p != &head; p = p->next) {
      if (p->data == a) {
        break;
      }
    }

    if (p == &head) {
      return -2;
    }

    Node *q = p->prev;
    Node *r = p->next;

    q->next = r;
    r->prev = q;

    delete p;

    return 0;
  }

  int deleteFirst() {
    Node *p = head.next;

    if (p == &head) {
      return -2;
    }

    Node *q = p->prev;
    Node *r = p->next;

    q->next = r;
    r->prev = q;

    delete p;

    return 0;
  }

  int deleteLast() {
    Node *p = head.prev;

    if (p == &head) {
      return -2;
    }

    Node *q = p->prev;
    Node *r = p->next;

    q->next = r;
    r->prev = q;

    delete p;

    return 0;
  }

  void print() {
    for (Node *p = head.next; p != &head; p = p->next) {
      cout << p->data;

      if (p->next != &head) {
        cout << ' ';
      } else {
        cout << endl;
      }
    }
  }
};

int main() {
  List L;

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    char com[20];
    cin >> com;
    ;

    if (com[0] == 'i') {
      int x;
      cin >> x;

      L.insert(x);
    } else if (com[6] == 'F') {
      L.deleteFirst();
    } else if (com[6] == 'L') {
      L.deleteLast();
    } else {
      int x;
      cin >> x;

      L.del(x);
    }
  }

  L.print();

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

char F[102][102];

void DFS(int Y, int X, char c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = c;

  DFS(Y - 1, X, c);
  DFS(Y - 1, X + 1, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y + 1, X - 1, c);
  DFS(Y, X - 1, c);
  DFS(Y - 1, X - 1, c);
}

int main() {
  int N, M;
  while (1) {
    cin >> N >> M;

    for (int y = 1; y <= N; y++) {
      for (int x = 1; x <= M; x++) {
        cin >> F[y][x];
      }
    }

    int cnt = 0;
    for (int y = 1; y <= N; y++) {
      for (int x = 1; x <= M; x++) {
        if (F[y][x] == '@') {
          cnt++;
          DFS(y, x, '@');
        }
      }
    }
    for (int y = 1; y <= N; y++) {
      for (int x = 1; x <= M; x++) {
        if (F[y][x] == '#') {
          cnt++;
          DFS(y, x, '#');
        }
      }
    }
    for (int y = 1; y <= N; y++) {
      for (int x = 1; x <= M; x++) {
        if (F[y][x] == '*') {
          cnt++;
          DFS(y, x, '*');
        }
      }
    }

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

#include <iostream>
#include <list>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  string coms;
  list<int> nums;
  int key;
  for (i = 0; i < n; i++) {
    cin >> coms;
    if (coms == "insert") {
      cin >> key;
      nums.push_front(key);
    } else if (coms == "delete") {
      cin >> key;
      for (auto itr = nums.begin(); itr != nums.end();) {
        if (*itr == key) {
          itr = nums.erase(itr);
          break;
        } else {
          itr++;
        }
      }
    } else if (coms == "deleteFirst") {
      nums.pop_front();
    } else if (coms == "deleteLast") {
      nums.pop_back();
    }
  }

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


Error: TLE

Fixed submission:

#include <iostream>
#include <list>
using namespace std;
int main() {
  int n, i, cnt = 0;
  cin >> n;
  string coms;
  list<int> nums;
  int key;
  for (i = 0; i < n; i++) {
    cin >> coms;
    if (coms == "insert") {
      cin >> key;
      nums.push_front(key);
    } else if (coms == "delete") {
      cin >> key;
      for (auto itr = nums.begin(); itr != nums.end();) {
        if (*itr == key) {
          itr = nums.erase(itr);
          break;
        } else {
          itr++;
        }
      }
    } else if (coms == "deleteFirst") {
      nums.pop_front();
    } else if (coms == "deleteLast") {
      nums.pop_back();
    }
  }

  for (auto itr = nums.begin(); itr != nums.end(); itr++) {
    cout << *itr;
    cnt++;
    if (cnt < nums.size())
      cout << " ";
  }
  cout << endl;
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: WA

Fixed submission:

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

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

    n--;
    if (n == 0)
      break;
  }
  int i = 0;
  for (list<int>::iterator it = A.begin(); it != A.end(); it++) {
    if (i++)
      printf(" ");
    printf("%d", *it);
  }
  printf("\\n");
  return 0;
}
Problem p02265 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

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

int main() {
  int n, inpnum;
  scanf("%d", &n);
  char comm[20];

  list<int> linkedlist;
  for (int comind = 0; comind < n; comind++) {
    scanf("%s", comm);

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

  int allsize = linkedlist.size();
  for (int i = 0; i < allsize;) {
    if (i++) {
      printf(" ");
    }
    printf("%d", linkedlist.front());
    linkedlist.pop_front();
  }

  printf("\\n");
}

Error: TLE

Fixed submission:

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

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

  list<int> linkedlist;
  for (int comind = 0; comind < n; comind++) {
    string comm;
    cin >> comm;
    if (comm == "insert") {
      int inpnum;
      cin >> inpnum;
      linkedlist.push_front(inpnum);
    } else if (comm == "delete") {
      int inpnum;
      cin >> inpnum;
      for (list<int>::iterator it = linkedlist.begin(); it != linkedlist.end();
           it++) {
        if (*it == inpnum) {
          linkedlist.erase(it);
          break;
        }
      }
    } else if (comm == "deleteFirst") {
      linkedlist.pop_front();
    } else {
      linkedlist.pop_back();
    }
  }

  int allsize = linkedlist.size();
  for (int i = 0; i < allsize;) {
    if (i++) {
      cout << " ";
    }
    cout << linkedlist.front();
    linkedlist.pop_front();
  }

  cout << endl;
}
Problem p02265 (C++) — buggy submission, verdict: Runtime Error

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

typedef std::deque<std::uint64_t> DType;

int main() {
  DType D;
  std::uint64_t N;
  std::uint64_t C;
  std::string S;
  std::cin >> C;

  DType::iterator it = D.begin();

  for (std::size_t i = 0; i < C; i++) {
    if (!(std::cin >> S))
      break;
    if (S[0] == 'i' || S[0] == 'I') { // insert
      std::cin >> N;
      D.push_front(N);
      continue;
    }
    if (S.size() == 6) { // delete
      std::cin >> N;
      auto it = std::find(D.begin(), D.end(), N);
      if (it != D.end())
        D.erase(it);
      continue;
    }
    if (S.size() == 11) { // deletefirst
      D.pop_front();
      continue;
    }
    if (S.size() == 10) { // deletelast
      D.pop_back();
      continue;
    }
  }

  for (auto it = D.begin(); it != D.end(); it++) {
    if (it != D.begin())
      std::cout << ' ';

    std::cout << *it;
  }

  std::cout << std::endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

typedef std::vector<std::uint64_t> DType;

int main() {
  DType D;
  std::uint64_t N;
  std::uint64_t C;
  std::string S;
  std::cin >> C;

  for (std::size_t i = 0; i < C; i++) {
    if (!(std::cin >> S))
      break;
    if (S[0] == 'i' || S[0] == 'I') { // insert
      std::cin >> N;
      D.push_back(N);
      continue;
    }
    if (S.size() == 6) { // delete
      std::cin >> N;
      auto it = std::find(D.begin(), D.end(), N);
      D.erase(it);
      continue;
    }
    if (S.size() == 11) { // deletefirst
      D.erase(D.begin());
      continue;
    }
    if (S.size() == 10) { // deletelast
      D.pop_back();
      continue;
    }
  }

  for (auto it = D.rbegin(); it != D.rend(); it++) {
    if (it != D.rbegin())
      std::cout << ' ';

    std::cout << *it;
  }

  std::cout << std::endl;

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

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

typedef std::list<std::uint64_t> DType;

int main() {
  DType D;
  std::uint64_t N;
  std::uint64_t C;
  std::string S;
  std::cin >> C;

  for (std::size_t i = 0; i < C; i++) {
    if (!(std::cin >> S))
      break;
    if (S[0] == 'i' || S[0] == 'I') { // insert
      std::cin >> N;
      D.insert(D.begin(), N);
      continue;
    }
    if (S.size() == 6) { // delete
      std::cin >> N;
      auto it = std::find(D.begin(), D.end(), N);
      if (it != D.end())
        D.erase(it);
      continue;
    }
    if (S.size() == 11) { // deletefirst
      D.pop_front();
      continue;
    }
    if (S.size() == 10) { // deletelast
      D.pop_back();
      continue;
    }
  }

  for (auto it = D.begin(); it != D.end(); it++) {
    if (it != D.begin())
      std::cout << ' ';

    std::cout << *it;
  }

  std::cout << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

typedef std::vector<std::uint64_t> DType;

int main() {
  DType D;
  std::uint64_t N;
  std::uint64_t C;
  std::string S;
  std::cin >> C;

  for (std::size_t i = 0; i < C; i++) {
    if (!(std::cin >> S))
      break;
    if (S[0] == 'i' || S[0] == 'I') { // insert
      std::cin >> N;
      D.insert(D.begin(), N);
      continue;
    }
    if (S.size() == 6) { // delete
      std::cin >> N;
      auto it = std::find(D.begin(), D.end(), N);
      if (it != D.end())
        D.erase(it);
      continue;
    }
    if (S.size() == 11) { // deletefirst
      D.erase(D.begin());
      continue;
    }
    if (S.size() == 10) { // deletelast
      D.pop_back();
      continue;
    }
  }

  for (auto it = D.begin(); it != D.end(); it++) {
    if (it != D.begin())
      std::cout << ' ';

    std::cout << *it;
  }

  std::cout << std::endl;

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

#include <algorithm>
#include <cstdio>
#include <list>

using namespace std;

int main() {
  int q, x;
  char com[20];

  list<int> v;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s", com);
    if (com[0] == 'i') {
      scanf("%d", &x);
      v.push_front(x);
    } else if (com[6] == 'L') {
      v.pop_back();
    } else if (com[6] == 'F') {
      v.pop_front();
    } else if (com[0] == 'd') {
      scanf("%d", &x);
      for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (*it == x) {
          v.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
    if (i++)
      printf(" ");
    printf("%d", *it);
  }
  printf("\\n");

  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

int main() {
  list<int> keys;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string query;
    cin >> query;
    if (query[0] == 'i') {
      int x;
      cin >> x;
      keys.push_front(x);
    } else if (query[0] == 'd') {
      if (query == "delete") {
        int x;
        cin >> x;
        for (auto iter = keys.begin(); iter != keys.end(); iter++) {
          if (*iter == x) {
            keys.erase(iter);
            break;
          }
        }
      } else if (query == "deleteFirst") {
        keys.erase(keys.begin());
      } else if (query == "deleteLast") {
        keys.erase(keys.end());
      }
    }
  }
  for (auto iter = keys.begin(); iter != keys.end(); iter++) {
    if (iter == keys.end()--)
      cout << *iter << endl;
    else
      cout << *iter << " ";
  }
}