import java.util.Scanner;

public class Abhi {
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
	
		int n = s.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int m = 0;
	
		for(int i = 0; i<n; i++) {
			a[i] = s.nextInt();
		}
		
		for(int i = 0; i<n; i++) {
			
			if(a[i] > 0) {
				
	           int j = i;
	           int max = 0;
	           while(a[j] > 0) {
	        	   
	        	   if(max < a[j]) {
	        		   
	        		   max = a[j];
	    
	        	   }
	        	   
	        	   if(j == n-1)
	        		   break;
	        	   
	        	   j++;
	        	   i = j-1;
	           }
	           
	           b[m] = max;
	           m++;
				
			}
			if(a[i] < 0) {
			
				 int j = i;
				 int max1 = -1000000;
		           while(a[j] < 0) {
		        	   
		        	   if(max1 < a[j]) {
		        		   
		        		   max1 = a[j];
		    
		        	   }
		        	   
		        	   if(j == n-1)
		        		   break;
		        	   
		        	   j++;
		        	   i = j-1;
		           }
		          
		           b[m] = max1;
		           m++;
			}
			
		}
		

		for(int i = 0; i<n; i++) {

			if(b[i] == 0) {
				break;
			}
			System.out.print(b[i]+" ");
			
		}
		
	}	
} 