CCCGuide

Problem S2: Heavy-Light Composition

2024 · S2 · Original problem · DMOJ

Problem Description

In a string containing only lowercase letters of the alphabet ("a" through "z"), we say a letter is heavy if it appears more than once in the string, and light otherwise.

We will be given a number of strings. For each string, we would like to determine whether the letters of the string alternate between light and heavy.

Input Specification

The first line of input will consist of two positive integers TT and NN, representing the number of strings and the length of each string.

The next TT lines each contain a sequence of NN lowercase letters of the alphabet.

The following table shows how the available 1515 marks are distributed:

MarksBounds on TTBounds on NNOther Restrictions
552≤T≤42 \le T \le 42≤N≤42 \le N \le 4Only the letters "a" and "b" will be used
552≤T≤102 \le T \le 102≤N≤302 \le N \le 30None
222≤T≤1002 \le T \le 1002≤N≤1002 \le N \le 100Only the letter "a" will be heavy; all other letters are light
332≤T≤10 0002 \le T \le 10\ 0002≤N≤100  2 \le N \le 100~~None

Output Specification

Output TT lines, where each line will be either T or F. If the ii-th input string does alternate between light and heavy letters, the ii-th line of output should be T; and otherwise, the ii-th line of output should be F.

Sample Input 1

3 4
abcb
bcbb
babc 

Output for Sample Input 1

T
F
T 

Explanation of Output for Sample Input 1

The first string is composed of a light letter, then a heavy letter, then a light letter, and then a heavy letter.

The second string ends in two consecutive heavy letters.

The third string is composed of a heavy letter, then a light letter, then a heavy letter, and then a light letter.

Sample Input 2

2 3
abc
bcb 

Output for Sample Input 2

F
T 

Explanation of Output for Sample Input 2

The first string is composed of all light letters.

The second string is composed of a heavy letter, then a light letter, and then a heavy letter.