#C3193. Malfunction Checker Based on Distinct Substrings

    ID: 46593 Type: Default 1000ms 256MiB

Malfunction Checker Based on Distinct Substrings

Malfunction Checker Based on Distinct Substrings

Problem Description:

Given a string s, define its number of distinct substrings as (\text{DS}(s)), which counts all unique contiguous substrings of s. For a given integer limit l, you are to check whether the string causes a malfunction. Specifically, if (\text{DS}(s) > l), the string causes a malfunction and you must output MALFUNCTION; otherwise, output NO MALFUNCTION.

For example, for s = "abc", the distinct substrings are "a", "b", "c", "ab", "bc", and "abc", so (\text{DS}(s)=6). Thus, if l is at least 6, there is no malfunction; if l is less than 6, a malfunction occurs.

inputFormat

Input Format:
The first line contains an integer t, the number of test cases.
Each of the next t lines contains an integer l and a string s separated by a space.

outputFormat

Output Format:
For each test case, print a single line containing NO MALFUNCTION if (\text{DS}(s) \leq l), or MALFUNCTION if (\text{DS}(s) > l).## sample

3
10 abc
5 ababa
1 a
NO MALFUNCTION

MALFUNCTION NO MALFUNCTION

</p>