CF1610D.Not Quite Lee
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lee couldn't sleep lately, because he had nightmares. In one of his nightmares (which was about an unbalanced global round), he decided to fight back and propose a problem below (which you should solve) to balance the round, hopefully setting him free from the nightmares.
A non-empty array b1,b2,…,bm is called good, if there exist m integer sequences which satisfy the following properties:
- The i -th sequence consists of bi consecutive integers (for example if bi=3 then the i -th sequence can be (−1,0,1) or (−5,−4,−3) but not (0,−1,1) or (1,2,3,4) ).
- Assuming the sum of integers in the i -th sequence is sumi , we want sum1+sum2+…+summ to be equal to 0 .
You are given an array a1,a2,…,an . It has 2n−1 nonempty subsequences. Find how many of them are good.
As this number can be very large, output it modulo 109+7 .
An array c is a subsequence of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements.
输入格式
The first line contains a single integer n ( 2≤n≤2⋅105 ) — the size of array a .
The second line contains n integers a1,a2,…,an ( 1≤ai≤109 ) — elements of the array.
输出格式
Print a single integer — the number of nonempty good subsequences of a , modulo 109+7 .
输入输出样例
输入#1
4 2 2 4 7
输出#1
10
输入#2
10 12391240 103904 1000000000 4142834 12039 142035823 1032840 49932183 230194823 984293123
输出#2
996
说明/提示
For the first test, two examples of good subsequences are [2,7] and [2,2,4,7] :
For b=[2,7] we can use (−3,−4) as the first sequence and (−2,−1,…,4) as the second. Note that subsequence [2,7] appears twice in [2,2,4,7] , so we have to count it twice.
Green circles denote (−3,−4) and orange squares denote (−2,−1,…,4) .For b=[2,2,4,7] the following sequences would satisfy the properties: (−1,0) , (−3,−2) , (0,1,2,3) and (−3,−2,…,3)