用c\c++编写
The Coolest Search EngineDescriptionThe Coolest Search Engine came out. It aggregates the ranks of all the well-known search engines and generate the coolest rank. How to decide a aggregated rank is the coolest acording to some ranks?Given a universe U, we just call an ordered sequence A containing all the elements in U as a list. And A(i) denote the rank of the ith element.Then we define SF distance between two lists. Formally, given two lists A and B, the SF distance between A and B is given byAnd the SF distance between A and some lists B1 ... Bm is given by Given some lists B1 ... Bm, A is the coolest aggregated rank if it has the least SF distance to B1 ... Bm.InputThe first line is the number of test cases c(1 ≤ c ≤ 100). The first line of each test case contains two integer n (1 ≤ n ≤ 100) and m(1 ≤ m ≤ 100) indicating the number of elements in U and the number of search engines. The following m lines each contains a sequence of n different integers, B(1) B(2) ... B(n)(0 ≤ B(i) ≤ n-1), indicating the rank result of one search engine.OutputFor each input test case, print the SF distance between the coolest aggregated rank and the given ranks.Sample Input2
3 2
0 1 2
0 2 1
3 2
0 1 2
2 1 0
Sample Output2
4