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 <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
// #define TEST
// //*******************************************************************************************************************************************

//?????????????????¨??§?????\\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout                                                                   \\
  dummy.str("");                                                               \\
  dummy.clear(stringstream::goodbit);                                          \\
  dummy // dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§????????????????????????????????????
//http://d.hatena.ne.jp/linden/20060427/p1
#endif

void deleteX(list<uint64_t> &list, int x) {
  for (auto itr = list.begin(); itr != list.end(); itr++) {
    if (*itr == x) {
      list.erase(itr);
      break;
    }
  }
}

int main(void) {
  list<uint64_t> list;
  uint64_t n;

  cin >> n;

  for (size_t i = 1; i <= n; i++) {
    string order;
    uint64_t x;

    if (!(cin >> order))
      break;

    //        dout << order << " " << x << endl;

    if (order[0] == 'i') {
      cin >> x;
      list.push_front(x);
      continue;
    } else if (order.size() == 6) {
      cin >> x;
      //            deleteX(list, x);
      auto it = find(list.begin(), list.end(), x);
      if (it != list.end())
        list.erase(it);
      continue;
    } else if (order.size() == 11) {
      list.pop_front();
      continue;
    } else if (order.size() == 10) {
      list.pop_back();
      continue;
    }
  }

  // display list
  //    dout << "---- display list ---- \\n";
  for (auto itr = list.begin(); itr != list.end(); itr++) {
    if (itr == list.begin()) {
      cout << *itr;
    } else {
      cout << " " << *itr;
    }
  }
  cout << endl;

  return 0;
}