// Arup Guha
// 12/27/2018
// Solution to 2018 December Gold Problem: Cowpatibility

import java.util.*;
import java.io.*;

public class cowpatibility {
	
	public static int n;
	public static int[][] likes;
	public static ArrayList[] subs;
	
	public static void main(String[] args) throws Exception {
		
		// Read in the raw data, and sort subsets.
		BufferedReader stdin = new BufferedReader(new FileReader("cowpatibility.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		n = Integer.parseInt(tok.nextToken());
		likes = new int[n][5];
		subs = new ArrayList[n];
		for (int i=0; i<n; i++) subs[i] = new ArrayList<Integer>();
		for (int i=0; i<n; i++) {
			tok = new StringTokenizer(stdin.readLine());
			for (int j=0; j<5; j++) 
				likes[i][j] = Integer.parseInt(tok.nextToken());
			Arrays.sort(likes[i]);
		}

		// Make a look up table for each subset.
		int id = 0;
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		
		// Store whether we add or subtract for each subset here (by subset id).
		int[] sign = new int[2000000];
		
		// Trying to save time...
		int[] lookup = new int[32];
		for (int i=0; i<5; i++)
			lookup[1<<i] = i;
		
		// Get each possible subset a cow can belong to.
		for (int i=0; i<n; i++) {
			
			// Go through each non-empty subset of this cow.
			String[] mysubs = new String[1<<5];
			mysubs[0] = "";
			for (int mask=1; mask<(1<<5); mask++) {
				
				// Build string version.
				int left = Integer.highestOneBit(mask);
				mysubs[mask] = mysubs[mask - left] + likes[i][lookup[left]]+".";
				
				// Map it now.
				int myid = -1;
				if (!map.containsKey(mysubs[mask])) {
					myid = id;
					map.put(mysubs[mask], id++);
				}
				
				// Deal with ints from the get go.
				if (myid == -1) myid = map.get(mysubs[mask]);
				subs[i].add(myid);
				sign[myid] = Integer.bitCount(mask)%2 == 1 ? 1 : -1;
			}
		}
		
		// Will store number of cows in each group.
		int[] numcows = new int[id];
		
		// Now go through cows again, to count up sizes of each subset.
		for (int i=0; i<n; i++) {
			
			// // Add 1 to the count of each subset of this cow.
			for (Integer tmp: (ArrayList<Integer>)subs[i])
				numcows[tmp]++;	
		}
		
		// Will store result.
		long res = 0;	
		
		// Now go through cows one last time.
		for (int i=0; i<n; i++) {
			
			// Will keep track of # of cows in this group.
			int tot = 0;
			
			// Run Inclusion-Exclusion here.
			for (Integer tmp: (ArrayList<Integer>)subs[i])
				tot += numcows[tmp]*sign[tmp];
			
			// Add in all cows not compatible with cow i.
			res = (res + n - tot);
		}		

		// Output to file.
		PrintWriter out = new PrintWriter(new FileWriter("cowpatibility.out"));
		out.println(res/2);
		out.close();		
		stdin.close();		
	}
}

