atcoder#ARC110B. [ARC110B] Many 110

[ARC110B] Many 110

Score : 400400 points

Problem Statement

Let SS be the concatenation of 101010^{10} copies of the string 110. (For reference, the concatenation of 33 copies of 110 is 110110110.)

We have a string TT of length NN.

Find the number of times TT occurs in SS as a contiguous substring.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • TT is a string of length NN consisting of 0 and 1.

Input

Input is given from Standard Input in the following format:

NN

TT

Output

Print the number of times TT occurs in SS as a contiguous substring.

4
1011
9999999999

SS is so long, so let us instead count the number of times 1011 occurs in the concatenation of 33 copies of 110, that is, 110110110. We can see it occurs twice:

  • 11 1011 01100110
  • 11011101 1011 00
22
1011011011011011011011
9999999993