#C2612. Taco Grouping Challenge

    ID: 45948 Type: Default 1000ms 256MiB

Taco Grouping Challenge

Taco Grouping Challenge

Given an integer \(K\) representing the number of groups and an integer \(N\) representing the number of citizens, along with an array of \(N\) integers representing the citizens' hobbies (each hobby is an integer in the range \([1, K]\)), determine whether it is possible to split the citizens into exactly \(K\) contiguous groups of equal size \(L = \frac{N}{K}\) such that for every hobby \(h\) (with \(1 \le h \le K\)), the total number of citizens having hobby \(h\) is divisible by \(L\). If it is possible, print "YES"; otherwise, print "NO".

Note: A contiguous group means that the citizens in that group appear consecutively in the original order. You may assume that the hobby values are valid and within the range from 1 to \(K\).

inputFormat

The first line contains an integer \(T\) that denotes the number of test cases. Each test case is described as follows:

  1. The first line of each test case contains two space-separated integers \(K\) and \(N\), where \(K\) is the number of groups and \(N\) is the number of citizens.
  2. The second line contains \(N\) space-separated integers representing the hobbies of the citizens.

It is guaranteed that \(N\) is a positive integer and the hobbies are integers in the range \([1, K]\).

outputFormat

For each test case, output a single line containing "YES" if it is possible to split the citizens as required; otherwise, output "NO".

## sample
3
2 6
1 1 2 2 1 2
3 9
1 2 3 1 2 3 1 2 3
2 5
1 1 2 2 1
YES

YES NO

</p>