QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#23865. Circle Cross Stamps

통계

Problem Description

JOI has $0$ or more of each of $3$ types of stamps: circle stamps, cross stamps, and circle-cross stamps. These are stamps that can print circle or cross marks on paper.

Using a circle stamp prints $1$ circle, and using a cross stamp prints $1$ cross. Using a circle-cross stamp prints a circle and a cross ($1$ of each) in a horizontal row, and by changing the orientation of the stamp, it can be printed either with the cross to the right of the circle or with the circle to the right of the cross.

JOI used each of the stamps he has exactly $1$ time in an appropriate order to print circles and crosses in a horizontal row on paper. The sequence of printed circles and crosses is represented by a string $S$. $S$ is a string of length $N$ consisting of O and X; if $S_i = $ O, it means that the $i$-th mark from the left among the marks printed by JOI is a circle, and if $S_i =$ X, it means that it is a cross ($1 \le i \le N$).

You do not know the number of stamps JOI has, but you know the sequence of circles and crosses printed by JOI. From the sequence of printed circles and crosses, find the maximum possible number of circle-cross stamps that JOI could have.

Constraints

  • $1 \le N \le 100000 (= 10^5)$
  • $S$ is a string of length $N$.
  • Each character of $S$ is O or X.

Input / Output

Input
The input is given from Standard Input in the following format:
$N$
$S$

Output
Output the maximum possible number of circle-cross stamps that JOI could have.

Sample Input / Output

Sample Input 1

5
OXXOX

Sample Output 1

2

The marks printed by JOI are, in order from the left, circle, cross, cross, circle, cross. If JOI has $0, 1, 2$ circle stamps, cross stamps, and circle-cross stamps respectively, he can print the marks in this way by using the stamps in the following order:

  • Use the $1$-st circle-cross stamp to print a circle and a cross in this order.
  • To the right of this, use the $2$-nd circle-cross stamp to print a cross and a circle in this order.
  • Finally, to the right of this, use the cross stamp to print a cross.

Since it is impossible for him to have $3$ or more circle-cross stamps, output $2$.


Sample Input 2

14
OXOXOXOXXOXOXO

Sample Output 2

7

Sample Input 3

10
OOOOOOOOOO

Sample Output 3

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.