406303: GYM102348 F The Number of Products

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. The Number of Productstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ integers.

You have to calculate three following values:

  1. the number of pairs of indices $$$(l, r)$$$ $$$(l \le r)$$$ such that $$$a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r$$$ is negative;
  2. the number of pairs of indices $$$(l, r)$$$ $$$(l \le r)$$$ such that $$$a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r$$$ is zero;
  3. the number of pairs of indices $$$(l, r)$$$ $$$(l \le r)$$$ such that $$$a_l \cdot a_{l + 1} \dots a_{r - 1} \cdot a_r$$$ is positive;
Input

The first line contains one integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^{5})$$$ — the number of elements in the sequence.

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{9} \le a_i \le 10^{9})$$$ — the elements of the sequence.

Output

Print three integers — the number of subsegments with negative product, the number of subsegments with product equal to zero and the number of subsegments with positive product, respectively.

ExamplesInput
5
5 -3 3 -1 0
Output
6 5 4
Input
10
4 0 -4 3 1 2 -4 3 0 3
Output
12 32 11
Input
5
-1 -2 -3 -4 -5
Output
9 0 6
Note

In the first example there are six subsegments having negative products: $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 2)$$$, $$$(2, 3)$$$, $$$(3, 4)$$$, $$$(4, 4)$$$, five subsegments having products equal to zero: $$$(1, 5)$$$, $$$(2, 5)$$$, $$$(3, 5)$$$, $$$(4, 5)$$$, $$$(5, 5)$$$, and four subsegments having positive products: $$$(1, 1)$$$, $$$(1, 4)$$$, $$$(2, 4)$$$, $$$(3, 3)$$$.

加入题单

上一题 下一题 算法标签: