This page is still under construction.

Parts of this page are still being built. What you see may change.

Fibonacci Strings

Time limit1sMemory limit1024 MB

Summary
Sum the orders (counts of letter a) of every substring of X that is a Fibonacci string, meaning it has no two adjacent a's, counting each occurrence separately.
Level

Hard8 of 10

Topics
String, Dynamic programming, Combinatorics, Prefix sum
Solved
No attempts yet

Problem

Aron likes Fibonacci numbers. He likes them so much that he got bored of the numbers themselves and decided to invent other combinatorial objects based on them instead.

His first invention is the Fibonacci string. A string consisting only of the letters aa and bb, with exactly nn letters aa and no two consecutive letters aa, is called a Fibonacci string of order nn.

Given a string XX of aas and bbs, compute the sum of the orders of all Fibonacci strings that occur as substrings of XX. If a string occurs multiple times in XX, its order is counted once for each occurrence.

Input

The judge reads input in the following format:

  • line 11: N
  • line 22: X

Output

The judge writes a single line containing the return value of fibonacci(N, X).

Constraints

  • 1≤N≤100 0001 \le N \le 100\,000

Examples1

  1. Example 1

    Input
    6
    abaaba
    
    Expected output
    12