#C3658. Longest Zero-Sum Subarray

    ID: 47109 Type: Default 1000ms 256MiB

Longest Zero-Sum Subarray

Longest Zero-Sum Subarray

You are given an array of integers. Your task is to find the longest contiguous subarray whose elements sum to zero. In case there are multiple subarrays with the same maximum length, you should output the one that occurs first in the array.

Let \( arr[0 \ldots n-1] \) be the input array. A contiguous subarray \( arr[i \ldots j] \) (with \( 0 \le i \le j < n \)) has a sum given by:

[ S = \sum_{k=i}^{j} arr[k] ]

Your task is to identify the subarray for which \( S = 0 \) and the length \( (j-i+1) \) is maximized. If no such subarray exists, output an empty result.

Note: Use stdin for input and print the result to stdout.

inputFormat

The first line contains an integer \( n \) indicating the number of elements in the array. The second line contains \( n \) space-separated integers representing the array elements.

outputFormat

Print the elements of the longest contiguous subarray that sums to zero separated by a space. If no such subarray exists, print an empty line.

## sample
7
1 2 -3 1 2 -3 3
1 2 -3 1 2 -3