Devil's Horn

5

1 votes
Implementation, Strings, Easy
Problem

Devil's Horn is a trademark sign in rock culture. It is when you straighten your index and pinky fingers, and clench your middle and ring fingers, with the thumb on top of the folded fingers.

A Devil Horn String (or DHS) is defined as a string, which starts with a '|', followed by a '\', then any number of the letter 'm' (zero included), and a '/' character, and ends with a '|'.

Strings "|\mm/|", "|\/|" and "|\m/|" are considered to be DHS, while strings "||", "|\/" or "|\/mm|" are not DHS. (Strings are without quotes)

You are given a string of given length n. You have to find the maximum length of DHS that can be formed from that string. To convert a string into DHS, you can delete any number of characters (even zero).

Note that you cannot insert new characters or change existing characters.

If it is impossible to convert the given string into a DHS, print "1" (without quotes).

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

INPUT:

The first line consists of n, the length of given string.

The second line consists of a string s, which consists of characters '|', '\', '/' and 'm'.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

OUTPUT:

You have to print the maximum length of DHS that can be formed from that string. If it is impossible to form a string, print -1.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

CONSTRAINTS: 

 1n105

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?