#include<iostream>
using namespace std;
struct Node {
int data;
Node* next = nullptr;
Node(int data, Node* next = nullptr) {
this->data = data;
this->next = next;
}
};
class Stack {
public:
Node* top = nullptr;
void push(int number) {
if (isEmpty()) {
top = new Node(number);
}
else {
Node* newTop = new Node(number, top);
top = newTop;
}
}
void pop() {
if (!isEmpty()) {
Node* oldTop = top;
top = top->next;
delete oldTop;
}
else {
throw std::underflow_error("Stack is empty");
}
}
int peek() const {
if (!isEmpty()) {
return top->data;
}
else {
throw std::underflow_error("Stack is empty");
}
}
bool isEmpty() const {
return top == nullptr;
}
};
void PrintStack(Stack s)
{
if (s.isEmpty()) return;
int x = s.peek();
s.pop();
PrintStack(s);
cout << x << " ";
s.push(x);
}
Stack s;
int main() {
int n;
cin >> n;
int num;
if (n > 0) {
cin >> num;
s.push(num);
}
bool flag = 0;
if (n > 1) {
cin >> num;
}
for (int i = 2; i <= n; )
{
while (s.peek() > 0) {
if (s.peek() + num == 0)
{
if (!s.isEmpty()) {
s.pop();
i++;
if (i > n) { flag = 1; break; }
cin >> num;
continue;
}
}
while (!s.isEmpty() && s.peek() + num < 0 && s.peek()>0) {
if (!s.isEmpty()) s.pop();
}
if (num > 0) {
s.push(num);
}
if ((s.isEmpty() && num < 0) || (num < 0 && s.peek() < 0)) {
s.push(num);
}
i++;
if (i > n) { flag = 1; break; }
cin >> num;
}
if (flag) break;
while (s.peek() < 0)
{
s.push(num);
i++;
if (i > n) break;
cin >> num;
}
}
if (!s.isEmpty()) PrintStack(s);
else cout << '\n';
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}