Description

Frosh commencing their studies at Waterloo have diverse interests, as evidenced by their desire to take various combinations of courses from among those available.

University administrators are uncomfortable with this situation, and therefore wish to offer a conformity prize to frosh who choose one of the most popular combinations of courses. How many frosh will win the prize?

Input

The input consists of several test cases followed by a line containing 0. Each test case begins with an integer 1 ≤ n ≤ 10000, the number of frosh. For each frosh, a line follows containing the course numbers of five distinct courses selected by the frosh. Each course number is an integer between 100 and 499.

The popularity of a combination is the number of frosh selecting exactly the same combination of courses. A combination of courses is considered most popular if no other combination has higher popularity.

Output

For each line of input, you should output a single line giving the total number of students taking some combination of courses that is most popular.

Sample Input

3
100 101 102 103 488
100 200 300 101 102
103 102 101 488 100
3
200 202 204 206 208
123 234 345 456 321
100 200 300 400 444
0

Sample Output

2
3
  
【题意】n个学生,每人5门课程代号(100~499)的组合,定义这些课程组合的重复次数为受欢迎度。问选受欢迎度最大的课程组合的学生人数是多少。
【解题思路】

将每个学生所选的5门课进行从小到大排序,拼起来组成一个15位的数。由于变换之后的数太大,所以要哈希一下在存储。接下来再判重即可。使用的是最常见的线性探测,大整数求余hash的方法。

【AC代码】

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
#define CLE(a,b) memset(a,b,sizeof(a))
#define MEC(a,b) memcpy(a,b,sizeof(a))
#define ll long long
const int ll mod = 100007;
ll Hash[mod],pos[mod],top[mod],x[mod];
int n;
int get_Hash(ll num)
{
    int tmp = (num%mod+mod)%mod;
    while(Hash[tmp]!=-1&&Hash[tmp]!=num)tmp = (tmp+1)%mod;
    return tmp;
}
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        ll ans = 0;
        CLE(top,0);CLE(Hash,-1);
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<5; j++)
            {
                scanf("%I64d",&x[j]);
            }
            sort(x,x+5);
            ll tmp = 0;
            for(int j=0; j<5; j++)
            {
                tmp = tmp*1000+x[j];
            }
            int in = get_Hash(tmp);
            Hash[in] = tmp;
            ans = max(ans,++top[pos[i]=in]);
        }
//        cout<<ans<<endl;
        int sum = 0;
        for(int j=0; j<n; j++)
        {
            if(top[pos[j]]==ans)sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}