#C10989. Maximum Real Coins Collection

    ID: 40254 Type: Default 1000ms 256MiB

Maximum Real Coins Collection

Maximum Real Coins Collection

You are given a sequence of coins represented by integers. Each coin is either real (a positive integer or zero) or a fake coin (a negative integer). The coins are collected sequentially. When you encounter the first fake coin, the coin collection stops immediately, and no coin after that is collected.

Your task is to determine the maximum number of real coins collected. Mathematically, if coins are represented as \(a_1, a_2, \dots, a_n\), find the maximum integer \(k\) (\(0 \le k \le n\)) such that:

\[ \forall i \in \{1,2,\dots,k\},\, a_i \ge 0 \quad \text{and} \quad \text{if } k < n, \; a_{k+1} < 0. \]

The answer is then \(k\). For example, for the coin sequence [1, 2, 3, -1, 4, 5], the answer is 3 because the first fake coin (\(-1\)) appears at the fourth position.

inputFormat

The first line of input contains an integer \(n\) denoting the number of coins. The second line contains \(n\) space-separated integers representing the coins in the order they are collected.

If \(n = 0\), the second line will be empty.

outputFormat

Output a single integer: the maximum number of real coins collected before encountering the first fake coin.

## sample
5
1 2 3 4 5
5