Mock CCC '18 Contest 5 S4 - Sparse Binary String Counting

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 0.6s
Memory limit: 1G

Problem type

Given a binary string of length N, where exactly K characters are ones, compute the number of substrings that have at least three ones.

Constraints

1N109

0K106

1aiN

ai are presented in sorted order.

KN

In tests worth 5 marks, you may assume K102.

In tests worth an additional 5 marks, you may assume K105.

Input Specification

The first line of the input contains two space-separated integers, N and K.

Each of the next K lines contains a single integer, ai, indicating that character ai of the string is a one.

Output Specification

Output a single integer, the number of substrings that contain at least three ones.

Sample Input

Copy
5 4
1
2
4
5

Sample Output

Copy
3

Comments

There are no comments at the moment.