#K73422. Treasure Hunter's Quest

    ID: 33972 Type: Default 1000ms 256MiB

Treasure Hunter's Quest

Treasure Hunter's Quest

In this problem, you are given a representation of a valley which is divided into n segments. Each segment is represented by a character:

  • T: a treasure
  • O: an obstacle
  • .: an empty segment
The hunter starts at the leftmost segment and moves towards the right. Along the way, the hunter collects any treasure ('T') encountered. However, if an obstacle ('O') is encountered, the hunter has the option to jump over exactly one obstacle during his journey. After using the jump, if any subsequent obstacle is encountered, the journey stops immediately.

Formally, let (n) be the length of the valley and (s) be the string representing the valley. The hunter collects all treasures before the first obstacle. When the first obstacle is met, he may choose to jump it and then begin collecting treasures thereafter until he encounters another obstacle, which terminates his journey. Your task is to determine the maximum number of treasures the hunter can collect.

Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The input consists of two lines:

  1. The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)), representing the length of the valley.
  2. The second line is a string of length \(n\) consisting of characters 'T', 'O', and '.', representing treasures, obstacles, and empty segments respectively.

outputFormat

Print a single integer representing the maximum number of treasures the hunter can collect.## sample

7
T..O.TT
3