Liars

Given a circular string of answers about whether the right neighbor is a liar, find the minimum number of liars consistent with all answers, or -1.

Medium4Brute forceImplementationArrayInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

NN people at an algorithm camp gather at the front of the classroom and sit in a circle. They are numbered 00 through N1N-1 counterclockwise.

Every participant is either honest or a liar. An honest person always tells the truth, and a liar always tells a lie.

The host asked each person whether the person sitting to their right is a liar. An honest person answers truthfully and a liar answers falsely. Both an honest person and a liar may refuse to answer.

Given the answers, write a program that prints the smallest possible number of liars if some assignment of honest people and liars produces exactly those answers, and 1-1 if no assignment does.

Input

The first line contains the number of people NN. (2N502 \le N \le 50)

The second line contains the answers as a string of length NN. The ii-th character from the left, counting from 00, is the answer of person ii.

An answer of L means the person said the one to their right is a liar, H means the person said that one is honest, and ? means the person refused to answer.

Output

If some assignment of honest people and liars produces the given answers, print the smallest possible number of liars. Otherwise print 1-1.

Note

The numbering runs counterclockwise, so the person sitting to the right of person ii is person (i+1)modN(i+1) \bmod N.