#include <iostream>
#include <string>
#include <exception>
using namespace std;
struct node{
int value;
node *next;
node():value(0), next(NULL){}
node(int value, node *next)
:value(value), next(next){}
};
struct _queue{
int _size;
node *first;
node *last;
_queue():_size(0), first(NULL), last(NULL){}
void push (int v){
node *new_node = new node(v, last);
if(_size == 0){
first = last = new_node;
}
else{
last->next = new_node;
last = new_node;
}
_size++;
}
void pop(){
if (_size > 0){
int val = first->value;
first = first->next;
_size--;
cout << val;
}
else throw 0;
}
void front(){
if (_size > 0) cout << first->value;
else throw 0;
}
int size(){
return _size;
}
void clear(){
while (_size > 0){
node *new_node = first->next;
delete first;
first = new_node;
_size--;
}
first = NULL;
last = NULL;
}
};
int main()
{
_queue q;
string s;
int n;
while (cin >> s){
if (s == "size"){
cout << q.size() << endl;
}
if (s == "push"){
cin >> n;
q.push(n);
cout << "ok" << endl;
}
if (s == "pop"){
try{
q.pop();
}
catch(int e){cout << "error";}
cout << endl;
}
if (s == "front"){
try {
q.front();
}
catch(int e){cout << "error";}
cout<<endl;
}
if (s == "clear"){
q.clear();
cout << "ok" << endl;
}
if (s == "exit"){
cout << "bye" <<endl;
return 0;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IG5vZGV7CiAgICBpbnQgdmFsdWU7CiAgICBub2RlICpuZXh0OwogICAgbm9kZSgpOnZhbHVlKDApLCBuZXh0KE5VTEwpe30KICAgIG5vZGUoaW50IHZhbHVlLCBub2RlICpuZXh0KQogICAgOnZhbHVlKHZhbHVlKSwgbmV4dChuZXh0KXt9Cn07CgpzdHJ1Y3QgX3F1ZXVlewogICAgaW50IF9zaXplOwogICAgbm9kZSAqZmlyc3Q7CiAgICBub2RlICpsYXN0OwogICAgX3F1ZXVlKCk6X3NpemUoMCksIGZpcnN0KE5VTEwpLCBsYXN0KE5VTEwpe30KCiAgICB2b2lkIHB1c2ggKGludCB2KXsKICAgICAgICBub2RlICpuZXdfbm9kZSA9IG5ldyBub2RlKHYsIGxhc3QpOwogICAgICAgIGlmKF9zaXplID09IDApewogICAgICAgICAgICBmaXJzdCA9IGxhc3QgPSBuZXdfbm9kZTsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgbGFzdC0+bmV4dCA9IG5ld19ub2RlOwogICAgICAgICAgICBsYXN0ID0gbmV3X25vZGU7CiAgICAgICAgfQogICAgICAgIF9zaXplKys7CiAgICB9CgogICAgdm9pZCBwb3AoKXsKICAgICAgICBpZiAoX3NpemUgPiAwKXsKICAgICAgICAgICAgaW50IHZhbCA9IGZpcnN0LT52YWx1ZTsKICAgICAgICAgICAgZmlyc3QgPSBmaXJzdC0+bmV4dDsKICAgICAgICAgICAgX3NpemUtLTsKICAgICAgICAgICAgY291dCA8PCB2YWw7CiAgICAgICAgfQogICAgICAgIGVsc2UgdGhyb3cgMDsKICAgIH0KCiAgICB2b2lkIGZyb250KCl7CiAgICAgICAgaWYgKF9zaXplID4gMCkgY291dCA8PCBmaXJzdC0+dmFsdWU7CiAgICAgICAgZWxzZSB0aHJvdyAwOwogICAgfQogICAgCiAgICBpbnQgc2l6ZSgpewogICAgICAgIHJldHVybiBfc2l6ZTsKICAgIH0KCiAgICB2b2lkIGNsZWFyKCl7CiAgICAgICAgd2hpbGUgKF9zaXplID4gMCl7CiAgICAgICAgICAgIG5vZGUgKm5ld19ub2RlID0gZmlyc3QtPm5leHQ7CiAgICAgICAgICAgIGRlbGV0ZSBmaXJzdDsKICAgICAgICAgICAgZmlyc3QgPSBuZXdfbm9kZTsKICAgICAgICAgICAgX3NpemUtLTsKICAgICAgICB9CiAgICAgICAgZmlyc3QgPSBOVUxMOwogICAgICAgIGxhc3QgPSBOVUxMOwogICAgfQp9OwoKCmludCBtYWluKCkKewogICAgX3F1ZXVlIHE7CiAgICBzdHJpbmcgczsKICAgIGludCBuOwogICAgd2hpbGUgKGNpbiA+PiBzKXsKICAgICAgICBpZiAocyA9PSAic2l6ZSIpewogICAgICAgICAgICBjb3V0IDw8IHEuc2l6ZSgpIDw8IGVuZGw7CiAgICAgICAgfQogICAgICAgIGlmIChzID09ICJwdXNoIil7CiAgICAgICAgICAgIGNpbiA+PiBuOwogICAgICAgICAgICBxLnB1c2gobik7CiAgICAgICAgICAgIGNvdXQgPDwgIm9rIiA8PCBlbmRsOwogICAgICAgIH0KICAgICAgICBpZiAocyA9PSAicG9wIil7CiAgICAgICAgICAgIHRyeXsKICAgICAgICAgICAgICAgIHEucG9wKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2F0Y2goaW50IGUpe2NvdXQgPDwgImVycm9yIjt9CiAgICAgICAgICAgIGNvdXQgPDwgZW5kbDsKICAgICAgICB9CiAgICAgICAgaWYgKHMgPT0gImZyb250Iil7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBxLmZyb250KCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2F0Y2goaW50IGUpe2NvdXQgPDwgImVycm9yIjt9CiAgICAgICAgICAgIGNvdXQ8PGVuZGw7CiAgICAgICAgfQogICAgICAgIGlmIChzID09ICJjbGVhciIpewogICAgICAgICAgICBxLmNsZWFyKCk7CiAgICAgICAgICAgIGNvdXQgPDwgIm9rIiA8PCBlbmRsOwogICAgICAgIH0KICAgICAgICBpZiAocyA9PSAiZXhpdCIpewogICAgICAgICAgICBjb3V0IDw8ICJieWUiIDw8ZW5kbDsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=