The Number of Products Gym - 102348F

 

The Number of Products

 Gym - 102348F 

You are given a sequence a1,a2,…,ana1,a2,…,an consisting of nn integers.

You have to calculate three following values:

  1. the number of pairs of indices (l,r)(l,r) (l≤r)(l≤r) such that al⋅al+1…ar−1⋅aral⋅al+1…ar−1⋅ar is negative;
  2. the number of pairs of indices (l,r)(l,r) (l≤r)(l≤r) such that al⋅al+1…ar−1⋅aral⋅al+1…ar−1⋅ar is zero;
  3. the number of pairs of indices (l,r)(l,r) (l≤r)(l≤r) such that al⋅al+1…ar−1⋅aral⋅al+1…ar−1⋅ar is positive;

Input

The first line contains one integer nn (1≤n≤2⋅105)(1≤n≤2⋅105) — the number of elements in the sequence.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109)(−109≤ai≤109) — 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.

Examples

Input

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,2), (1,3)(1,3), (2,2)(2,2), (2,3)(2,3), (3,4)(3,4), (4,4)(4,4), five subsegments having products equal to zero: (1,5)(1,5), (2,5)(2,5), (3,5)(3,5), (4,5)(4,5), (5,5)(5,5), and four subsegments having positive products: (1,1)(1,1), (1,4)(1,4), (2,4)(2,4), (3,3)(3,3).

 

简单dp

#include<bits/stdc++.h>
using namespace std;
long long dp[200050][2],a[200050];
//dp[i][0]以当前数字为结尾的负数序列
//dp[i][1]以当前数字为结尾的正数序列
int main()
{
    long long i,j,m,n,ans1,ans2,ans3;
    scanf("%lld",&n);
    for(i = 1; i <= n; i++)
    {
        scanf("%lld",&a[i]);
    }
    for(i = 1; i <= n; i++)
    {
        if(a[i]==0)
            dp[i][0] = dp[i][1] = 0;
        else if(a[i]<0)
        {
            dp[i][0] = dp[i-1][1]+1;
            dp[i][1] = dp[i-1][0];
        }
        else
        {
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1]+1;
        }
    }
    ans1 = ans2 = ans3 = 0;
    for(i = 1; i <=n; i++)
    {
        ans1 += dp[i][0];
        ans2+= dp[i][1];
    }
    ans3 = n*(n+1)/2 -ans1-ans2;
    printf("%lld %lld %lld\n",ans1,ans3,ans2);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值