JOIOJI

JOI Spring Training Camp 2013/14
Original Statement / Submission Site

Problem Statement

Mr. JOIOJI is JOI-kun's uncle. He likes his name, which contains exactly two occurrences of each of the letters J, O, and I.

Recently, Mr. JOIOJI had a child. He wants to give his child a name that, like his own, consists only of the letters J, O, and I, with each of the three letters occurring exactly the same number of times.

Mr. JOIOJI possesses a scroll that has been passed down through his family for generations. A poem is written on the scroll. The poem is a string of length N consisting only of the three letters J, O, and I.

Among all contiguous substrings of the poem containing exactly the same number of Js, Os, and Is, Mr. JOIOJI intends to choose the longest one as the name of his child.

Task

Given the poem written on Mr. JOIOJI's scroll, determine the maximum length of a contiguous substring containing exactly the same number of Js, Os, and Is.

Input

The input is given from standard input in the following format:

N
S

Output

Print one integer: the maximum length of a contiguous substring of the poem containing exactly the same number of Js, Os, and Is. If no such nonempty substring exists, print 0.

Constraints

Subtasks

Subtask 1 [5 points]

Subtask 2 [15 points]

Subtask 3 [80 points]

There are no additional constraints.

Sample Input 1

10
JOIIJOJOOI

Sample Output 1

6

Explanation of Sample 1

In this sample, the scroll contains the poem JOIIJOJOOI of length 10.

The poem contains the contiguous substring IIJOJO, which has exactly two occurrences of each of J, O, and I. There is no contiguous substring containing at least three occurrences of each letter in equal numbers. Therefore, the answer is the length of IIJOJO, which is 6.

Sample Input 2

8
IOIIJIIO

Sample Output 2

0

Explanation of Sample 2

The poem contains no contiguous substring satisfying the condition, so the output is 0.

Sample Input 3

20
JJIOOIJIJOIOJIOJOOIJ

Sample Output 3

15