import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main(){

    int a[];
    int n;
    while(readf("%d\n",&n)){
	writef("input = %d\n",n);
	if(n == 0){
	    //writeln(a[0]);
	    writef("output = %d\n",a[$-1]);
	    a = a[0..$-1];
	}else{
	    a ~= n;
	}
    }
}