## Mock CCC '22 1 S2 - IU

View as PDF

Points: 5 (partial)
Time limit: 0.25s
Memory limit: 1G

Problem type

Kaitlyn is the world's biggest IU fan. One day, she is bored and buys magnets. of them have the letter I on them and of them have the letter U on them. She arranges them on the fridge to spell IU repeated times.

Sadly, her archnemesis, Sylvia, has broken into her apartment and rearranged the magnets because she is not an IU fan.

Kaitlyn wants to fix the magnets so that it spells IU repeatedly. However, Kaitlyn is tired, so the only operation she can do is swap two adjacent magnets.

Compute the minimum number of operations Kaitlyn needs to make this happen.

#### Constraints

In tests worth 1 mark, .

In tests worth an additional 4 marks, .

#### Input Specification

The first line contains a single integer .

The second line contains a string of characters. It is guaranteed that of them are I and of them are U.

#### Output Specification

Output an integer , the minimum number of operations needed to rearrange the magnets as desired. If it is impossible to do so, output -1.

#### Sample Input

2
IUUI

#### Sample Output

1