아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Another Wine Tasting Event

시간 제한0.5초메모리 제한1024 MB

요약
길이 2n-1인 와인 문자열이 주어질 때, 길이가 n 이상인 n개의 서로 다른 구간이 모두 정확히 같은 수의 흰 와인을 포함하도록 하는 x를 구한다.
난이도

보통10점 중 7점

유형
문자열, 조합론
정답자
아직 제출이 없습니다

문제

After the first successful edition, Gabriella has been asked to organize a second wine tasting event. There will be 2n−12n - 1 bottles of wine arranged in a row, each of which is either red wine or white wine.

This time, Gabriella has already chosen the type and order of all the bottles. The types of the wines are represented by a string ss of length 2n−12n - 1. For each 1≤i≤2n−11 ≤ i ≤ 2n - 1, it holds that s_i=s\_i = R if the ii-th bottle is red wine, and s_i=s\_i = W if the ii-th bottle is white wine.

Exactly nn critics have been invited to attend. The critics are numbered from 11 to nn. Just like last year, each critic jj wants to taste an interval of wines, that is, the bottles at positions a_j,a_j+1,…,b_ja\_j , a\_j+1, \dots , b\_j for some 1≤a_j≤b_j≤2n−11 ≤ a\_j ≤ b\_j ≤ 2n - 1. Moreover, they have the following additional requirements:

  • each of them wants to taste at least nn wines, that is, it must hold that b_j−a_j+1≥nb\_j - a\_j + 1 ≥ n;
  • no two critics must taste exactly the same wines, that is, if j≠kj \ne k it must hold that a_j≠a_ka\_j \ne a\_k or b_j≠b_kb\_j \ne b\_k.

Gabriella knows that, since the event is held in a coastal region of Italy, critics are especially interested in the white wines, and don’t care much about the red ones. (Indeed, white wine is perfect to accompany seafood.) Thus, to ensure fairness, she would like that all critics taste the same number of white wines.

Help Gabriella find an integer xx (with 0≤x≤2n−10 ≤ x ≤ 2n - 1) such that there exists a valid assignment of intervals to critics where each critic tastes exactly xx white wines. It can be proved that at least one such xx always exists.

입력

The first line contains the integer nn (1≤n≤1061 ≤ n ≤ 10^6) — where 2n−12n - 1 is the number of bottles, and nn is the number of critics.

The second line contains a string s of length 2n−12n - 1 that represents the arrangement of the wines — the ii-th character of ss (1≤i≤2n−11 ≤ i ≤ 2n - 1) is R for a red wine and W for a white wine.

출력

Print an integer xx — the number of white wines that each critic will taste.

It can be proved that at least one solution exists. If multiple solutions exist, any of them will be accepted.

예제2

  1. 예제 1

    입력
    5
    RWWRRRWWW
    
    예상 출력
    2
    
  2. 예제 2

    입력
    1
    R
    
    예상 출력
    0