Hello 2023
A
Hall of Fame
Codeforces
800
原题
←B →
翻译中…

Thalia is a Legendary Grandmaster in chess. She has $n$ trophies in a line numbered from $1$ to $n$ (from left to right) and a lamp standing next to each of them (the lamps are numbered as the trophies).

翻译中…

A lamp can be directed either to the left or to the right, and it illuminates all trophies in that direction (but not the one it is next to). More formally, Thalia has a string $s$ consisting only of characters 'L' and 'R' which represents the lamps' current directions. The lamp $i$ illuminates:

翻译中…
  • trophies $1,2,\ldots, i-1$ if $s_i$ is 'L';
  • trophies $i+1,i+2,\ldots, n$ if $s_i$ is 'R'.
翻译中…

She can perform the following operation at most once:

翻译中…
  • Choose an index $i$ ($1 \leq i \lt n$);
  • Swap the lamps $i$ and $i+1$ (without changing their directions). That is, swap $s_i$ with $s_{i+1}$.
翻译中…

Thalia asked you to illuminate all her trophies (make each trophy illuminated by at least one lamp), or to tell her that it is impossible to do so. If it is possible, you can choose to perform an operation or to do nothing. Notice that lamps cannot change direction, it is only allowed to swap adjacent ones.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 10\,000$). The description of the test cases follows.

翻译中…

The first line of each test case contains a positive integer $n$ ($2 \leq n \leq 100\,000$)  — the number of trophies.

翻译中…

The second line of each test case contains a string $s$ of length $n$ consisting only of characters 'L' and 'R'  — the $i$-th character describes the direction of the $i$-th lamp.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $100\,000$.

翻译中…

Output

翻译中…

For each test case print $-1$ if it is impossible to illuminate all trophies by performing one operation (or doing nothing). Otherwise, print $0$ if you choose not to perform the operation (i.e., the trophies are illuminated by the initial positioning of the lamps), or an index $i$ ($1 \leq i \lt n$) if you choose to swap lamps $i$ and $i+1$.

翻译中…

If there are multiple answers, print any.

翻译中…

Note

翻译中…

In the first example, it is possible to swap lamps $1$ and $2$, or do nothing. In any case, the string "LL" is obtained. Not all trophies are illuminated since trophy $2$ is not illuminated by any lamp  — lamp $1$ illuminates nothing and lamp $2$ illuminates only the trophy $1$.

翻译中…

In the second example, it is necessary to swap lamps $1$ and $2$. The string becomes "RL". Trophy $1$ is illuminated by lamp $2$ and trophy $2$ is illuminated by lamp $1$, hence it is possible to illuminate all trophies.

翻译中…

In the third example, all trophies are initially illuminated  — hence, not performing any operation is a valid solution.

翻译中…

In the last two examples performing swaps is not necessary as all trophies are illuminated initially. But, the presented solutions are also valid.

翻译中…

样例

Input #1
6
2
LL
2
LR
2
RL
2
RR
7
LLRLLLR
7
RRLRRRL
Output #1
-1
1
0
-1
3
6
InputCopy OutputCopy
题目信息
题号
1779A
所属比赛
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。