/**
 * 
 */
package cs2020;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;


class Pair {
	public HashSet<IntegerArr> hs = new HashSet<IntegerArr>();
	public int count = 0;
}

class IntegerArr {
	public Integer[] cArr;
	public int hashCode() {
		// TODO Auto-generated method stub
		return Arrays.hashCode(cArr);
	}
	
	public boolean equals(Object obj) {
		IntegerArr IA = (IntegerArr) obj;
		return Arrays.equals(cArr, IA.cArr);
	}
}

/**
 * @author vishnu
 *
 */
public class PremPS5 {

	/**
	 * 
	 */
	public PremPS5() {
		// TODO Auto-generated constructor stub
	}

	public static void main(String[] args) {
		for(String s : args) {
			StopWatch sw = new StopWatch();
			sw.start();
			HashMap<Integer, Pair> hm = new HashMap<Integer, Pair>(500);
			try {
				FileReader dataFile = new FileReader(s);
		        BufferedReader bufferedDataFile = new BufferedReader(dataFile);
		        bufferedDataFile.readLine(); // Dont care about size, discarding
		        
		        String line;
		        int length;
	        	Pair p;
	        	IntegerArr IA;
	        	
		        while ((line = bufferedDataFile.readLine()) != null) {
		        	length = line.length();
		        	IA = new IntegerArr();
	        		IA.cArr = freqChar(line);
	        		
		        	p = hm.get(length);
		        	if(p==null) {
		        		p = new Pair();
		        		p.hs.add(IA);
		        		hm.put(length, p);
		        	} else {
			        	if(p.hs.contains(IA)) { p.count++; }
			        	else {
			        		p.hs.add(IA);
			        	}
		        	}
				}
		        
		        int count = 0;
		        for(Pair pp : hm.values()) {
		        	if(pp.count==0) continue;
		        	count += (pp.count*(pp.count+1))/2;
		        }
		        sw.stop();
		        System.out.println(count + " " + sw.getTime());
			} catch (Exception e) {
				System.out.println(e);
			}
		}
	}
	
	private static String stringSort(String str) {
		if(str==null) return null;
		char[] a = str.toCharArray();
		Arrays.sort(a);
		return new String(a);
	}
	
	private static Integer[] freqChar(String str) {
		if(str==null) return null;
		Integer[] arr = new Integer[256];
		for (int i = 0; i < arr.length; i++) {
			arr[i]=0;
		}
		for (int i = 0; i < str.length(); i++) {
			arr[str.charAt(i)]++;
		}
		return arr;
	}
}
@@ -188,26 +188,22 @@
 HashSet%3C
-IntegerArr
+String
 %3E hs = n
@@ -217,24 +217,19 @@
 Set%3C
-IntegerArr
+String
 %3E();
-%0A%09
+ 
 publ
@@ -253,268 +253,8 @@
 %0A%7D%0A%0A
-class IntegerArr %7B%0A%09public Integer%5B%5D cArr;%0A%09public int hashCode() %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09return Arrays.hashCode(cArr);%0A%09%7D%0A%09%0A%09public boolean equals(Object obj) %7B%0A%09%09IntegerArr IA = (IntegerArr) obj;%0A%09%09return Arrays.equals(cArr, IA.cArr);%0A%09%7D%0A%7D%0A%0A
 /**%0A
@@ -855,33 +855,35 @@
    %09
-IntegerArr IA;%0A%09        %09
+%0A%09        %09int hmcount = 0;
 %0A%09%09 
@@ -904,16 +904,27 @@
 (line = 
+stringSort(
 buffered
@@ -943,16 +943,17 @@
 dLine())
+)
  != null
@@ -995,91 +995,8 @@
 ();%0A
-%09%09        %09IA = new IntegerArr();%0A%09        %09%09IA.cArr = freqChar(line);%0A%09        %09%09%0A
 %09%09  
@@ -1092,26 +1092,28 @@
  %09%09p.hs.add(
-IA
+line
 );%0A%09%09       
@@ -1134,16 +1134,39 @@
 th, p);%0A
+%09%09        %09%09hmcount++;%0A
 %09%09      
@@ -1206,18 +1206,20 @@
 ontains(
-IA
+line
 )) %7B p.c
@@ -1249,50 +1249,23 @@
 lse 
-%7B%0A%09%09%09        %09%09p.hs.add(IA);%0A%09%09%09        %09%7D
+p.hs.add(line);
 %0A%09%09 
@@ -1392,16 +1392,57 @@
 ntinue;%0A
+%09%09        %09System.out.println(pp.count);%0A
 %09%09      
@@ -1568,16 +1568,31 @@
 etTime()
+ +%22 %22 + hmcount
 );%0A%09%09%09%7D 
@@ -1812,268 +1812,5 @@
 %0A%09%7D%0A
-%09%0A%09private static Integer%5B%5D freqChar(String str) %7B%0A%09%09if(str==null) return null;%0A%09%09Integer%5B%5D arr = new Integer%5B256%5D;%0A%09%09for (int i = 0; i %3C arr.length; i++) %7B%0A%09%09%09arr%5Bi%5D=0;%0A%09%09%7D%0A%09%09for (int i = 0; i %3C str.length(); i++) %7B%0A%09%09%09arr%5Bstr.charAt(i)%5D++;%0A%09%09%7D%0A%09%09return arr;%0A%09%7D%0A
 %7D

Revert "A charFreq array solution"