Mixed Messages
시간 제한2초메모리 제한2048 MB
최종 문자열이 주어질 때, 코드워드 spbsu를 포함한 메시지들의 문자를 서로 다른 메시지 사이에서만 인접 교환한 최소 횟수를 구한다.
문제
Nikita received some messages today. One of the messages was the code word "spbsu". Before and after the code word, there may have been any number of other messages as well. The other messages are arbitrary strings of lowercase English letters.
All the messages were sent via a secret channel, one by one. So, the string in the channel initially was a concatenation of all the messages.
However, being secret, the channel may introduce noise: different messages may interfere with each other. Formally, the noise comes in form of swaps. In each swap, the channel selects and exchanges two adjacent letters in the string that initially belonged to different messages. For letters of any particular message, the relative order is preserved.
After all swaps, the resulting string is received by Nikita. Given the resulting string, find the minimum possible number of swaps made by the channel.
입력
The first line contains a single integer : the number of received characters ().
The next line contains a string consisting of lowercase English letters: the resulting string received by Nikita. It is guaranteed that this string is the result of the process described above.
출력
Output a single integer: the answer to the problem.