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

#include <iostream>
using namespace std;
#define LEN 100005

typedef struct Process {
  char name[100];
  int time;
} P;

P Q[LEN];
int head, tail;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {

  int n, q;
  cin >> n >> q;

  head = 1;
  tail = 1;

  for (int i = 0; i < n; ++i) {
    P p;
    cin >> p.name >> p.time;
    enqueue(p);
  }

  P user;
  int total = 0;
  while (head != tail) {
    user = dequeue();
    int cost = 0;
    cost = min(q, user.time);
    user.time -= cost;
    total += cost;
    if (0 < user.time)
      enqueue(user);
    else
      cout << user.name << " " << total << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

struct Process {
  string name;
  int time;
  int flag;
};

int main() {

  int n, q;
  cin >> n >> q;
  struct Process *p = new Process[n];

  for (int i = 0; i < n; ++i) {
    cin >> p[i].name >> p[i].time;
    p[i].flag = 0;
  }

  int m = 0;
  int total = 0;
  for (;;) {
    if (p[m].flag == 0) {
      p[m].time -= q;
      total += q;
      if (p[m].time <= 0) {
        total += p[m].time;
        cout << p[m].name << " " << total << endl;
        p[m].time = 0;
        p[m].flag = 1;
      }
    }
    for (int i = 0; i < n; ++i) {
      if (p[i].time == 0) {
        if (i == n - 1)
          return 0;
      } else {
        break;
      }
    }
    ++m;
    if (m == n)
      m = 0;
  }

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

#include <stdio.h>

// ?????\\???????§???????
typedef struct {
  char name[11];
  int time;
} Queue;

int main() {
  //??\\???
  int n, q;
  scanf("%d%d", &n, &q);

  int size = 2 * n; //?????\\???????????????
  Queue Queue[size];
  int pre = 0, rear = 0, cnt = 0; // pre:enqueue, rear:inqueue, cnt:????????????
  for (rear = 0; rear < n; ++rear)
    scanf("%s %d", Queue[rear].name, &Queue[rear].time);

  //????????¨??????
  while (pre != rear) {
    if (Queue[pre].time <=
        q) { // if( Queue[pre].time == q ){ inqueue????????? }
      cnt += Queue[pre].time;
      printf("%s %d\\n", Queue[pre].name, cnt);
    } else {
      cnt += q;
      Queue[pre].time -= q;
      Queue[rear] = Queue[pre]; // inqueue
      rear = (rear + 1) % size; //?¬????inqueue???
    }

    //?¬????dequeue???
    pre = (pre + 1) % size;
  }

  return 0;
}

Error: 0

Fixed submission:

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 20000

typedef struct {
  char name[20];
  int time;
} Process;

typedef struct {
  int start_p;
  int end_p;
  int num;
  Process *q;
} Queue;

Process *pop(Queue *que) {

  if (que->num != 0) {
    que->num--;
    if (que->start_p + 1 > MAX) {
      que->start_p = 0;
    }
    return &(que->q[que->start_p++]);
  } else {
    return NULL;
  }
}

void push(Queue *que, Process *p) {

  if (que->end_p + 1 > MAX) {
    que->end_p = 0;
  }
  que->q[que->end_p++] = *p;
  que->num++;
}

int main(int argc, const char *argv[]) {

  // Input
  int t_slice, p_num;
  int i;
  int ctime = 0;
  Queue que;
  Process *p;

  scanf("%d %d", &p_num, &t_slice);

  que.start_p = 0;
  que.num = p_num;
  que.end_p = p_num;
  que.q = (Process *)malloc(sizeof(Process) * MAX);
  for (i = 0; i < p_num; i++) {
    scanf("%s %d", que.q[i].name, &(que.q[i].time));
  }

  while ((p = pop(&que)) != NULL) {

    if (p->time > t_slice) {
      p->time -= t_slice;
      push(&que, p);
      ctime += t_slice;
    } else {
      printf("%s %d\\n", p->name, ctime + p->time);
      ctime += p->time;
    }
  }

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

#include <iostream>
#define LENGTH 100005

using namespace std;

typedef struct {
  string name;
  int time;
} Queue;

Queue Q[LENGTH];
int head, tail, n;

Queue dequeue() {
  Queue x = Q[head];
  if (head + 1 == LENGTH)
    head = 0;
  else
    head++;
  return x;
}

void enqueue(Queue x) {
  Q[tail] = x;
  if (tail + 1 == LENGTH)
    tail = 0;
  else
    tail++;
}

int main() {
  int q, finish_time = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    cin >> Q[i].name >> Q[i].time;
  head = 0;
  tail = n;
  while (head != tail) {
    Queue x = dequeue();
    finish_time += min(q, x.time);
    x.time -= min(q, x.time);
    if (x.time > 0)
      enqueue(x);
    else
      cout << x.name << " " << finish_time << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#define LENGTH 100001

using namespace std;

typedef struct {
  string name;
  int time;
} Queue;

Queue Q[LENGTH];
int head, tail, n;

Queue dequeue() {
  Queue x = Q[head];
  if (head + 1 == LENGTH)
    head == 0;
  else
    head++;
  return x;
}

void enqueue(Queue x) {
  Q[tail] = x;
  if (tail + 1 == LENGTH)
    tail = 0;
  else
    tail++;
}

int main() {
  int q, finish_time = 0;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    cin >> Q[i].name >> Q[i].time;
  head = 0;
  tail = n;
  while (head != tail) {
    if (Q[head].time > q) {
      Q[head].time -= q;
      finish_time += q;
      Queue x = Q[head];
      dequeue();
      enqueue(x);
    } else {
      finish_time += Q[head].time;
      cout << Q[head].name << " " << finish_time << endl;
      dequeue();
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

#define MAX 100005

using namespace std;

struct process {
  int time;
  string name;
};

class my_queue {
private:
  int head, tail;
  process queue[MAX];

public:
  my_queue() {
    head = 0;
    tail = 0;
  }

  bool isEmpty() { return head == tail; }

  bool isFull() { return head == (tail + 1) % MAX; }

  void enqueue(process n) {
    if (isFull()) {
      cout << "Queue is full." << endl;
      return;
    }
    queue[tail++] = n;

    if (tail == MAX)
      tail = 0;

    return;
  }

  process dequeue() {
    if (isEmpty()) {
      cout << "Queue is empty." << endl;
      exit(-1);
    }

    process ret = queue[head];

    if (head + 1 == MAX)
      head = 0;
    else
      head++;

    return ret;
  }
};

int main(void) {
  my_queue queue;
  process proc;
  int n, q;
  int time = 0;

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> proc.name >> proc.time;
    queue.enqueue(proc);
  }

  while (!queue.isEmpty()) {
    proc = queue.dequeue();
    if (proc.time <= q) {
      time += proc.time;
      cout << proc.name << " " << time << endl;
    } else {
      proc.time = proc.time - q;
      queue.enqueue(proc);
      time += q;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

#define MAX 100005

using namespace std;

struct process {
  int time;
  string name;
};

class my_queue {
private:
  int head, tail;
  process queue[100000];

public:
  my_queue() {
    head = 0;
    tail = 0;
  }

  bool isEmpty() { return head == tail; }

  bool isFull() { return head == (tail + 1) % MAX; }

  void enqueue(process n) {
    if (isFull()) {
      cout << "Queue is full." << endl;
      return;
    }
    queue[tail++] = n;

    if (tail == MAX)
      tail = 0;

    return;
  }

  process dequeue() {
    if (isEmpty()) {
      cout << "Queue is empty." << endl;
      exit(-1);
    }

    process ret = queue[head];

    if (head + 1 == MAX)
      head = 0;
    else
      head++;

    return ret;
  }
};

int main(void) {
  my_queue queue;
  process proc;
  int n, q;
  int time = 0;

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> proc.name >> proc.time;
    queue.enqueue(proc);
  }

  while (!queue.isEmpty()) {
    proc = queue.dequeue();
    if (proc.time <= q) {
      time += proc.time;
      cout << proc.name << " " << time << endl;
    } else {
      proc.time = proc.time - q;
      queue.enqueue(proc);
      time += q;
    }
  }

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

#include <stdio.h>
#include <string.h>
#define maxn 100000

typedef struct nameandtime {
  char name[10 + 2];
  int time;
} RW;

RW Q[maxn];
int head, tail;

void enqueue(RW x) {
  Q[tail] = x;
  tail = (tail + 1) % maxn;
}

RW dequeue() {
  RW x = Q[head];
  head = (head + 1) % maxn;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
  int q, t = 0, n;
  RW u;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }
  head = 1;
  tail = n + 1;
  while (head != tail) {
    u = dequeue();
    int c = min(q, u.time);
    u.time -= c;
    t += c;
    if (u.time > 0)
      enqueue(u);
    else
      printf("%s %d\\n", u.name, t);
  }
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define maxn 100000 + 5

typedef struct nameandtime {
  char name[10 + 2];
  int time;
} RW;

RW Q[maxn];
int head, tail, n;

void enqueue(RW x) {
  Q[tail] = x;
  tail = (tail + 1) % maxn;
}

RW dequeue() {
  RW x = Q[head];
  head = (head + 1) % maxn;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
  int q, t = 0;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }
  head = 1;
  tail = n + 1;
  while (head != tail) {
    RW u = dequeue();
    int c = min(q, u.time);
    u.time -= c;
    t += c;
    if (u.time > 0)
      enqueue(u);
    else
      printf("%s %d", u.name, t);
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <array>
#include <iostream>

using namespace std;

struct Process {
  string name;
  int time;
};

class ProcessQueue {
public:
  ProcessQueue() : head(), tail(), queue(){};
  virtual ~ProcessQueue(){};

  bool push(Process &process) {
    if (isFull()) {
      return false;
    }
    queue[head] = process;
    head++;
    if (head == MAX) {
      head = 0;
    }
    return true;
  }

  Process &pop() {
    if (isEmpty()) {
      // TODO: throw exception.
    }
    Process &value = queue[tail];
    tail++;
    if (tail == MAX) {
      tail = 0;
    }
    return value;
  }

  bool isEmpty() { return head == tail; }

  bool isFull() { return (head + tail) == MAX; }

private:
  static const int MAX = 100000;
  array<Process, MAX> queue;
  int head;
  int tail;
};

static void inputProcess(ProcessQueue &processQueue, int n) {
  Process in;
  for (int i = 0; i < n; i++) {
    cin >> in.name >> in.time;
    processQueue.push(in);
  }
}

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

  ProcessQueue processQueue;
  inputProcess(processQueue, n);

  int total = 0;
  while (!processQueue.isEmpty()) {
    Process now = processQueue.pop();
    if (now.time <= q) {
      total += now.time;
      cout << now.name << ' ' << total << endl;
    } else {
      now.time -= q;
      total += q;
      processQueue.push(now);
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <array>
#include <iostream>

using namespace std;

struct Process {
  string name;
  int time;
};

class ProcessQueue {
public:
  ProcessQueue(){};
  virtual ~ProcessQueue(){};

  bool push(Process &process) {
    if (isFull()) {
      return false;
    }
    queue[head] = process;
    head++;
    if (head == MAX) {
      head = 0;
    }
    return true;
  }

  Process &pop() {
    if (isEmpty()) {
      // TODO: throw exception.
    }
    Process &value = queue[tail];
    tail++;
    if (tail == MAX) {
      tail = 0;
    }
    return value;
  }

  bool isEmpty() { return head == tail; }

  bool isFull() { return (head + tail) == MAX; }

private:
  static const int MAX = 100000;
  array<Process, MAX> queue;
  int head;
  int tail;
};

static void inputProcess(ProcessQueue &processQueue, int n) {
  Process in;
  for (int i = 0; i < n; i++) {
    cin >> in.name >> in.time;
    processQueue.push(in);
  }
}

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

  ProcessQueue processQueue;
  inputProcess(processQueue, n);

  int total = 0;
  while (!processQueue.isEmpty()) {
    Process now = processQueue.pop();
    if (now.time <= q) {
      total += now.time;
      cout << now.name << ' ' << total << endl;
    } else {
      now.time -= q;
      total += q;
      processQueue.push(now);
    }
  }

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

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

class Process {
  int time;
  string name;

public:
  Process(int t, char *n) {
    time = t;
    name = n;
  }
  int take(int n) {
    time -= n;
    if (time > 0)
      return -1; //?¶???±?????????
    else
      return time + n;
  }
  string getname() { return name; }
};

int main() {
  int quontam, num, now = 0;
  queue<Process> processes;

  scanf("%d %d", &num, &quontam);

  for (int i = 0; num > i; i++) {
    char str[11];
    int time;
    scanf("%s %d", str, &time);
    processes.push(Process(time, str));
  }
  while (!processes.empty()) {
    int taken = processes.front().take(quontam);
    if (taken == -1) {
      now += quontam;
      processes.push(processes.front());
    } else {
      now += taken;
      printf("%s %d\\n", processes.front().getname().c_str(), now);
    }
    processes.pop();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

class Roundrobin {
private:
  int count, r;
  int num[100000];
  char rabel[100000][11];

public:
  Roundrobin() {
    count = 0;
    r = 0;
  }
  void setround(int ro) { r = ro; }
  void add(char *name, int n) {
    num[count] = n;
    strcpy(rabel[count], name);
    count++;
  }
  int pick(char *name) {
    int ret = num[0];
    strcpy(name, rabel[0]);
    for (int i = 1; count > i; i++) {
      num[i - 1] = num[i];
      strcpy(rabel[i - 1], rabel[i]);
    }
    count--;
    return ret;
  }
  void dow() {
    char name[3];
    int n, time = 0;
    while (count) {
      n = pick(name);
      n = n - r;
      if (n > 0) {
        add(name, n);
        time += r;
      } else {
        time += r + n;
        printf("%s %d\\n", name, time);
      }
    }
  }
};

int main() {
  int n, q, i, num;
  char rabel[3];
  Roundrobin robin;
  scanf("%d %d", &n, &q);
  robin.setround(q);
  for (i = 0; n > i; i++) {
    scanf("%s %d", &rabel, &num);
    robin.add(rabel, num);
  }
  robin.dow();
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int maxn = 100000 + 10;
int n, q;
struct Item {
  char name[12];
  int time;
};

int main() {
  //    freopen("in.txt","r",stdin);
  scanf("%d%d", &n, &q);
  queue<Item *> que;
  for (int i = 0; i < n; i++) {
    getchar();
    Item *item = new Item();
    scanf("%s%d", &item->name, &item->time);
    que.push(item);
  }
  int total_time = 0;
  while (!que.empty()) {
    Item *curItem = que.front();
    que.pop();
    if (curItem->time > q) {
      curItem->time -= q;
      que.push(curItem);
      total_time += q;
    } else {
      total_time += curItem->time;
      printf("%s %d\\n", curItem->name, total_time);
      delete curItem;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int maxn = 100000 + 10;
int n, q;
struct Item {
  char name[12];
  int time;
};

int main() {
  //    freopen("in.txt","r",stdin);
  scanf("%d%d", &n, &q);
  queue<Item> que;
  for (int i = 0; i < n; i++) {
    getchar();
    Item item;
    scanf("%s%d", &item.name, &item.time);
    que.push(item);
  }
  int total_time = 0;
  while (!que.empty()) {
    Item &curItem = que.front();
    que.pop();
    if (curItem.time > q) {
      curItem.time -= q;
      que.push(curItem);
      total_time += q;
    } else {
      total_time += curItem.time;
      printf("%s %d\\n", curItem.name, total_time);
    }
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int head, tail;
const int num = 100005;
typedef struct pp {
  char name[11];
  int t;
} p;
p s[num];
void enqueue(p a) {
  s[tail] = a;
  tail = (1 + tail) % num;
}
p dequeue() {
  p b = s[head];
  head = (1 + head) % num;
  return b;
}

int main() {
  int n, q, i, sum = 0;
  cin >> n;
  cin >> q;
  for (i = 0; i < n; i++) {
    cin >> s[i].name >> s[i].t;
  }
  head = 0;
  tail = n;
  while (head != tail) {
    p c = dequeue();
    int j = min(q, c.t);
    c.t -= j;
    sum += j;
    if (c.t > 0)
      enqueue(c);
    else
      cout << c.name << ' ' << sum << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int head, tail;
typedef struct pp {
  char name[11];
  int t;
} p;
p s[100005];
void enqueue(p a) {
  s[tail] = a;
  tail++;
}
p dequeue() {
  p b = s[head];
  head++;
  return b;
}

int main() {
  int n, q, i, sum = 0;
  cin >> n;
  cin >> q;
  for (i = 0; i < n; i++) {
    cin >> s[i].name >> s[i].t;
  }
  head = 0;
  tail = n;
  while (head != tail) {
    p c = dequeue();
    int j = min(q, c.t);
    c.t -= j;
    sum += j;
    if (c.t > 0)
      enqueue(c);
    else
      cout << c.name << ' ' << sum << endl;
  }
  return 0;
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

int que[100000];
int head = 0;
int tail = 0;
void enq(int a) {
  que[tail] = a;
  tail = (tail + 1) % 100000;
}

int deq() {
  int h = head;
  head = (head + 1) % 100000;
  return que[h];
}

bool empty() { return head == tail; }

int main() {
  int n, q;
  char name[100000][11];
  int time[100000];
  int clock = 0;

  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", name[i], &time[i]);
    enq(i);
  }

  while (!empty()) {
    int i = deq();
    if (time[i] <= q) {
      clock += time[i];
      time[i] = 0;
      printf("%s %d\\n", name[i], clock);
    } else {
      clock += q;
      time[i] -= q;
      enq(i);
    }
  }
}

Error: 0

Fixed submission:

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

int que[100000];
int head = 0;
int tail = 0;
void enq(int a) {
  que[tail] = a;
  tail = (tail + 1) % 100000;
}

int deq() { return que[head++]; }

bool empty() { return head == tail; }

int main() {
  int n, q;
  char name[100000][11];
  int time[100000];
  int clock = 0;

  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", name[i], &time[i]);
    enq(i);
  }

  while (!empty()) {
    int i = deq();
    if (time[i] <= q) {
      clock += time[i];
      time[i] = 0;
      printf("%s %d\\n", name[i], clock);
    } else {
      clock += q;
      time[i] -= q;
      enq(i);
    }
  }
}
Problem p02264 (C++) — buggy submission, verdict: Runtime Error

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

struct node {
  string name;
  int time;
};

int main(int argc, char *argv[]) {
  int n, q;
  int runtime = 0;
  cin >> n >> q;
  queue<node> in_queue;
  queue<node> out_queue;

  for (int i = 0; i < n; i++) {
    node input;
    cin >> input.name >> input.time;
    in_queue.push(input);
  }

  while (!in_queue.empty()) {
    if (in_queue.front().time <= q) {
      runtime += in_queue.front().time;
      in_queue.front().time = runtime;
      out_queue.push(in_queue.front());
      in_queue.pop();

    } else {
      runtime += q;
      in_queue.front().time -= q;
      in_queue.push(in_queue.front());
      in_queue.pop();
    }
  }

  while (!out_queue.empty()) {
    cout << out_queue.front().name << " " << out_queue.front().time << endl;
    out_queue.pop();
  }

  return 0;
}

Error: 0

Fixed submission:

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

struct node {
  string name;
  int time;
};

int main(int argc, char *argv[]) {
  int n, q;
  int runtime = 0;
  cin >> n >> q;
  queue<node> in_queue, out_queue;

  for (int i = 0; i < n; i++) {
    node input;
    cin >> input.name >> input.time;
    in_queue.push(input);
  }

  while (!in_queue.empty()) {
    for (int i = 0; i < n; i++) {
      if (in_queue.front().time <= q) {
        runtime += in_queue.front().time;
        in_queue.front().time = runtime;
        out_queue.push(in_queue.front());
        in_queue.pop();

      } else {
        runtime += q;
        in_queue.front().time -= q;
        in_queue.push(in_queue.front());
        in_queue.pop();
      }
    }
  }

  while (!out_queue.empty()) {
    cout << out_queue.front().name << " " << out_queue.front().time << endl;
    out_queue.pop();
  }

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

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

#pragma warning(disable : 4996)

using namespace std;

int main() {
  int n, v;

  string c;

  list<int> l;

  scanf("%d", &n);

  for (int i = 0; i < n;) {
    cin >> c;

    if (c[0] == 'i') {
      scanf("%d", &v);

      l.push_front(v);
    } else if (c.size() == 11) {
      l.pop_front();
    } else if (c.size() == 10) {
      l.pop_back();
    } else {
      scanf("%d", &v);

      list<int>::iterator it = l.begin();

      while (it != l.end()) {
        if (*it == v) {
          l.erase(it);
          break;
        }

        it++;
      }
    }

    i++;
  }

  list<int>::iterator it = l.begin();

  while (it != l.end()) {
    if (it == l.begin()) {
      printf("%d", *it);
    } else {
      printf(" %d", *it);
    }

    it++;
  }

  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <list>
#include <string>

#pragma warning(disable : 4996)

using namespace std;

int main() {
  int n, v;

  string c;

  list<int> l;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s", c.c_str());

    if (c[0] == 'i') {
      scanf("%d", &v);

      l.push_front(v);
    } else if (c.size() == 11) {
      l.pop_front();
    } else if (c.size() == 10) {
      l.pop_back();
    } else {
      scanf("%d", &v);

      list<int>::iterator it = l.begin();

      while (it != l.end()) {
        if (*it == v) {
          l.erase(it);
          break;
        }

        it++;
      }
    }
  }

  list<int>::iterator it = l.begin();

  while (it != l.end()) {
    if (it == l.begin()) {
      printf("%d", *it);
    } else {
      printf(" %d", *it);
    }
  }

  printf("\\n");

  return 0;
}