import java.util.*;

public class RemoveZeroSumSequences {
    
        static class ListNode {
                    int val;
                            ListNode next;
                            
                                    ListNode(int val) {
                                                    this.val = val;
                                    }
        }
        
        
            public static ListNode buildLinkedList(int[] arr) {
                        ListNode dummy = new ListNode(0);
                                ListNode current = dummy;
                                        for (int num : arr) {
                                                        current.next = new ListNode(num);
                                                                    current = current.next;
                                        }
                                                return dummy.next;
            }
            
                public static ListNode removeZeroSumSublists(ListNode head) {
                            Map<Integer, ListNode> prefixMap = new HashMap<>();
                                    ListNode dummy = new ListNode(0);
                                            dummy.next = head;
                                                    int prefixSum = 0;
                                                            ListNode current = dummy;
                                                            
                                                                    while (current != null) {
                                                                                    prefixSum += current.val;
                                                                                                prefixMap.put(prefixSum, current);
                                                                                                            current = current.next;
                                                                    }
                                                                    
                                                                            prefixSum = 0;
                                                                                    current = dummy;
                                                                                            while (current != null) {
                                                                                                            prefixSum += current.val;
                                                                                                                        ListNode node = prefixMap.get(prefixSum);
                                                                                                                                    if (node != current) {
                                                                                                                                                        current.next = node.next;
                                                                                                                                    }
                                                                                                                                                current = current.next;
                                                                                            }
                                                                                            
                                                                                                    return dummy.next;
                }
                
 public static void printLinkedList(ListNode head) {
             if (head == null) {
                             System.out.println("-1");
                                         return;
             }
             
                     ListNode current = head;
                             boolean hasOutput = false;
                                     while (current != null) {
                                                     System.out.print(current.val + " ");
                                                                 current = current.next;
                                                                             hasOutput = true;
                                     }
                                     
                                             if (!hasOutput) {
                                                             System.out.println("-1");
                                             }
 }
 
     public static void main(String[] args) {
                 Scanner sc = new Scanner(System.in);
                 
                         try {
                                         int n = Integer.parseInt(sc.nextLine().trim());
                                                     String[] elements = sc.nextLine().trim().split("\s+");
                                                     
                                                                 if (elements.length != n) {
                                                                                     System.out.println("Invalid input");
                                                                                                     return;
                                                                 }
                                                                 
                                                                             int[] nums = new int[n];
                                                                                         for (int i = 0; i < n; i++) {
                                                                                                             try {
                                                                                                                                     nums[i] = Integer.parseInt(elements[i]);
                                                                                                                                                     } catch (NumberFormatException e) {
                                                                                                                                                                             System.out.println("Invalid input");
                                                                                                                                                                                                 return;
                                                                                                                                                     }
                                                                                         }
                                                                                         
                                                                                                     ListNode original = buildLinkedList(nums);
                                                                                                                 ListNode modified = removeZeroSumSublists(original);
                                                                                                                 
                                                                                                                             List<Integer> inputList = new ArrayList<>();
                                                                                                                                         for (int num : nums) inputList.add(num);
                                                                                                                                                     List<Integer> outputList = new ArrayList<>();
                                                                                                                                                                 ListNode temp = modified;
                                                                                                                                                                             while (temp != null) {
                                                                                                                                                                                                 outputList.add(temp.val);
                                                                                                                                                                                                                 temp = temp.next;
                                                                                                                                                                             }
                                                                                                                                                                             
                                                                                                                                                                                         if (inputList.equals(outputList)) {
                                                                                                                                                                                                             System.out.println("-1");
                                                                                                                                                                                         } else {
                                                                                                                                                                                                             for (int val : outputList) {
                                                                                                                                                                                                                                     System.out.print(val + " ");
                                                                                                                                                                                                             }
                                                                                                                                                                                         }
                                                                                                                                                                                         
                         } catch (Exception e) {
                                         System.out.println("Invalid input");
                         }
     }
}