#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
const int N = 200005;
// 前缀和 除了1的数字 连续的1
ll sum[N], num[N], oneCnt[N];
int n = 1;
int main()
{
int k;
cin >> k;
for(int i = 0; i < k; i++){
int tmp;
cin >> tmp;
if(tmp == 1){
sum[n]++;
oneCnt[n]++;
}
else{
sum[n] += sum[n - 1] + tmp;
num[n] = tmp;
n++;
}
}
// 先把自身的情况算进去
int ans = k;
// 计算所有数字的和
ll m = sum[n - 1] + oneCnt[n];
for(int i = 1; i < n; i++){
ll p = num[i];
for(int j = i + 1; j < n; j++){
// 计算乘积
p *= num[j];
//如果乘积已经大于m,即最大和,就无解
if(p > m){
break;
}
//计算乘积与和的差值
ll diff = p - sum[j] + sum[i - 1] + oneCnt[i];
//如果差值为0,就是一个解
if(diff == 0){
ans++;
}
//如果差值不为0,我们可以拿两侧的1来补位
else if(oneCnt[i] + oneCnt[j + 1] >= diff && diff > 0){
ll le = min(diff, oneCnt[i]);
ll ri = min(diff, oneCnt[j + 1]);
ans += le + ri - diff + 1;
}
}
}
cout << ans << endl;
return 0;
}
02-01
619