#K9161. Counting Constant Temperature Subarrays

    ID: 38014 Type: Default 1000ms 256MiB

Counting Constant Temperature Subarrays

Counting Constant Temperature Subarrays

You are given a list of (p) temperature measurements and an integer (n). Your task is to count the number of contiguous subarrays of length (n) in which all elements are identical. In other words, find the number of indices (i) such that (0 \leq i \leq p - n) and (A[i] = A[i+1] = \cdots = A[i+n-1]). Formally, the condition can be stated as:

[ \forall j \in {0, 1, \dots, n-1},; A[i] = A[i+j] ]

The problem requires that input is read from standard input (stdin) and the output is written to standard output (stdout).

inputFormat

The first line of input contains two integers (p) and (n), where (p) is the number of temperature measurements and (n) is the length of the subarray to check. The second line contains (p) space-separated integers representing the temperature measurements.

outputFormat

Output a single integer, the count of subarrays of length (n) where all elements are the same.## sample

7 3
5 5 6 6 6 5 5
1