Day 2 - Queen of Qing

3.2

9 votes
Easy
Problem

The new queen of Qing Dynasty is The Queen Colilico .
She is very fond of her name.
She orders everyone in Qing to present her a COLILICO string.

A string is called COLILICO string if it follows the following conditions-
• It can be sliced into exactly four parts of equal length. (CO LI LI CO)
• The first part is identical to last part.
• The second part is identical to third part.

Little Fuji also has a string and wants to present it to Queen but he doesn’t know whether it’s a COLILICO string or not.

Help Fuji to present his string to queen at minimum cost.

Following are rules/costs to manipulate any string in Qing:-

• Characters of any particular part can be shuffled within that part without any cost.

• Characters cannot be transferred from one part to another.

• Replacing any character of string with a new one costs 1 Unit.

INPUT:-

 

The first line of input contains a positive integer Q denoting number of Queries.

The first line of each query contains a positive integer L denoting length of string.

The next line of the query contains a string of length L.

OUTPUT:-

Print “YES” (without quotes) if there is no cost to convert the string to COLILICO String.

Else print "NO" (without quotes) followed by an integer denoting the minimum cost.

 

 

 

CONSTRAINTS

1Q100000

4L200000

(L is always a multiple of 4)

String only consists of lower case letters of english alphabet.

Sum of L over all queries ≤ 1000000

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The first string is obviously not a COLILICO String. The minimum cost to convert it into COLILICO String is 2. One of the ways is to change c to b and d to a. The resulting String will be abba.

The second string is already a COLILICO String.

 

Participants are requested to keep themself updated with the announcements of the contest.

Editor Image

?