QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 128 MB Total points: 100

#11291. Salad Bar

統計

Bytea went to a salad bar. There are fruits one next to another on the bar counter. Specifically, these are apples and oranges. Bytea can pick any contiguous part of the line of fruits for her salad.

The fruits she chooses will be added to the salad either from left to right or from right to left. As Bytea loves oranges, she requires that throughout the salad making process, the number of oranges in it should always be no smaller than the number of apples, regardless of whether these are added % from left to right or from right to left. Help Bytea out by writing a program that will find the longest contiguous part of the line of fruits that satisfies her requirements.

Input Format

The first line of the standard input contains a single integer $n$ ($1 \le n \le 1\,000\,000$), denoting the number of fruits. The next line contains a string of $n$ characters $a_{1}a_{2}…a_{n}$ ($a_{i} \in \{j, p\}$). These stand for Polish names of apples and oranges: jab\l{ka} and pomara\'ncze). Consequently, if $a_{i}=j$, then the $i$-th fruit in a line is an apple, and otherwise it is an orange.

Output Format

The first and only line of the standard output should contain a single integer equal to the number of fruits in the longest contiguous part of the line that satisfies Bytea's requirements. Note that it could be the case that 0 is the correct result.

Example

Input

6
jpjppj

Output

4

Notes

Once the leftmost and the rightmost apples are discarded, Bytea can order a salad out of all remaining fruits.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.