public static void main(String args[]) throws Throwable{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		for(int N;(N=parseInt(in.readLine().trim()))!=0;){
			TreeMap<int[],Integer> mapa=new TreeMap<int[],Integer>(new Comparator<int[]>(){
				public int compare(int[] o1,int[] o2){
					for(int i=0;i<o1.length;i++)if(o1[i]!=o2[i])return o1[i]-o2[i];
					return 0;
				}
			});
			int max=0;
			for(int i=0;i<N;i++) {
				int[] s=new int[5];
				StringTokenizer st=new StringTokenizer(in.readLine());
				for(int j=0;j<5;j++)s[j]=parseInt(st.nextToken());
				Arrays.sort(s);
				Integer a=mapa.get(s);
				if(a==null)a=0;
				a++;
				max=max(max,a);
				mapa.put(s,a);
			}
			int sol=0;
			for(Entry<int[],Integer> entry:mapa.entrySet())
				if(entry.getValue()==max)
					sol+=entry.getValue();
			System.out.println(sol);
		}
		System.out.print(new String(sb));
	}