给定一个序列a1,a2,…,由n个非零整数组成(即ai≠0)。
请计算以下两个值:
指数对(l,r)(l≤r)的数目,使得al⋅al+1…ar−1⋅ar为负;
指数对(l,r)(l≤r)的数目,使得al⋅al+1…ar−1⋅ar为正;
The first line contains one integer n (1≤n≤2⋅105) — the number of elements in the sequence.
The second line contains n integers a1,a2,…,an (−109≤ai≤109;ai≠0) — the elements of the sequence.
Output
Print two integers — the number of subsegments with negative product and the number of subsegments with positive product, respectively.
Examples
Input
5
5 -3 3 -1 1
Output
8 7
Input
10
4 2 -4 3 1 2 -4 3 2 3
Output
28 27
Input
5
-1 -2 -3 -4 -5
Output
9 6
分析:先考虑全部为正的序列,则正积段为n+(n-1)+…+1种取法,所以正负积段总和为n * (n + 1) / 2,求出正积段即可求出负积段
在此基础上,我们只考虑正负,不考虑乘积的结果,所以令正数为0负数为1,用前缀和统计奇偶,维护两个桶前缀和分别为奇数和偶数的个数,
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int