#K58637. Longest Magical Subsequence

    ID: 30687 Type: Default 1000ms 256MiB

Longest Magical Subsequence

Longest Magical Subsequence

You are given a sequence of n integers. A subsequence is defined as a selection of elements from the sequence in their original order. In this problem, a subsequence is said to be magical if:

  • All the elements in the subsequence are distinct.
  • The sum of the elements is positive, i.e. $$\sum_{i=1}^{k} a_i > 0$$.

Your task is to determine the length of the longest magical subsequence that can be extracted from the original sequence.

Note: Since any positive integer is greater than zero, the longest magical subsequence in many cases will be the set of all distinct positive numbers from the sequence.

inputFormat

The first line contains an integer n ($1\leq n\leq 10^5$), the number of elements in the sequence. The second line contains n space-separated integers, which can be positive, negative, or zero.

outputFormat

Output a single integer, which is the length of the longest magical subsequence.

## sample
5
4 -1 2 -3 5
3