Bruce String

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

You are given T strings S1,S2,,ST consisting of lowercase letters. In one operation, you may swap any two adjacent characters in a string. For each string, compute the minimum number of operations required to make bruce a substring of that string.

Constraints

1T4×104

5|Si|2×105, where |Si| denotes the number of characters in Si.

The sum of the lengths of the T strings does not exceed 2×105.

Each string has at least one occurrence of each of the characters b, r, u, c, and e.

Subtask 1 [20%]

The sum of the lengths of the T strings does not exceed 10.

Subtask 2 [80%]

No additional constraints.

Input Specification

The first line contains an integer T, the number of strings.

The ith of the next T lines contains a string Si.

Output Specification

On the ith line output a single integer, the minimum number of operations required to make bruce a substring of Si.

Sample Input

Copy
3
buncher
bestcomputerprogrammingteacher
bruce

Sample Output

Copy
7
15
0

Comments

There are no comments at the moment.