|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||5||4||3||75.000%|
Sarah and Patricia are young, very gifted sisters. Ever since they learned arithmetic in preschool, they have been bothering their mother Marguerite day and night to practice their calculations. Marguerite bought the two girls an arithmetic practice book, which has n pages and a positive integer on each page. Those integers can be used for practicing arithmetic calculations. Marguerite hopes that the book can keep the two girls busy for a while so that she can work on her other chores.
Sarah and Patricia need to know whether their calculated answers are right, but Marguerite does not have the time to check their work. She therefore comes up with the clever idea of adversarial toddler training. Marguerite knows that Sarah is good at addition and Patricia is talented in multiplication. So she first chooses a range of consecutive book pages (at least two), and then asks Sarah to calculate the sum of the integers on these pages, and asks Patricia to calculate the product of these integers. If she chooses the pages carefully, then the two girls’ answers would be the same, and she can simply let Sarah and Patricia compare their answers!
As Sarah and Patricia do not want to practice on the same range multiple times, Marguerite wants to know in how many different ways she can select a range of pages for her toddler training (and when to buy a new practice book).
The input has a single integer n (2 ≤ n ≤ 2 · 105) on the first line. The second line has n positive integers giving the numbers in the arithmetic practice book ordered by the pages. None of these integers are larger than 109.
Output a single integer, the number of ways for Marguerite to choose a range of at least two consecutive pages so that Sarah’s answer matches Patricia’s.
5 2 2 1 2 3
8 1 2 4 1 1 2 5 1
4 5 6 7 8