## DMOPC '19 Contest 3 P3 - Majority

View as PDF

Points: 12
Time limit: 1.4s
Memory limit: 128M

Author:
Problem type

In preparation for an upcoming election, Najya has polled of her friends on whether they decide on voting for candidate or candidate . In her poll, she learned that the friend is a supporter of candidate . Being a supporter of candidate , she wants to know how many ways she can remove any number of people (possibly none) from the beginning and then remove any number of people (possibly none) from the end of her list such that a majority of her remaining friends are supporters of candidate .

#### Input Specification

The first line contains a single integer, .
The second line contains space-separated integers, .

#### Output Specification

Output one integer, the number of ways she can remove people from her list such that a majority of her remaining friends are supporters of candidate .

#### Sample Input 1

5
1 2 2 1 2

#### Sample Output 1

2

#### Sample Input 2

7
1 2 1 1 1 2 1

#### Sample Output 2

22