Pen Pineapple Apple Pen

Given a string of A, P, and p, find the maximum number of disjoint subsequence occurrences of the pattern p, P, A, p in order.

Medium5GreedyStringDynamic programmingNo attempts yetTime limit1sMemory limit32 MB

Problem

Apples, pineapples, and pens are lined up in a row. You may group four consecutive objects without changing their order. Four objects count as one group only when they appear in the order pen, pineapple, apple, pen. One pen can belong to at most one group. The order pen, apple, pineapple, pen does not count as a group.

Input

The first line gives the total number of objects nn (1n10000001 \le n \le 1000000).

The second line gives the list of objects as a string of length nn. An apple is written as A, a pineapple as P, and a pen as p, distinguishing uppercase and lowercase.

Output

Print the maximum number of groups that can be made.