import java.util.*;
import java.io.*;

public class Compare {
  static int table_size;
  int n; // number of collisions
  int total; // total number of entries
  String[] hashTable;

  Compare(int size) {
    table_size = size;
    n = 0;
    total = 0;
    hashTable = new String[table_size];
  }

  // use string length as a hash function
  static int hash1(String s) {
    return compress(s.length());
  }

  // adding the components of a string
  static int hash2(String s) {
    int hash = 0;
    for (int i = 0; i < s.length(); i++)
      hash += s.charAt(i);
    return compress(hash);
  }

  // hashing the first three characters
  static int hash3(String s) {
    int hash = 0;
    for (int i = 0; i < s.length() && i < 3; i++)
      hash = 27*hash + s.charAt(i);
    return compress(hash);
  }

  // hashing the whole string
  static int hash4(String s) {
    int hash = 0;
    for (int i = 0; i < s.length(); i++)
      hash = 27*hash + s.charAt(i);
    return compress(hash);
  }

  // shifting bits
  static int hash5(String s) {
    int hash = 0;
    for (int i = 0; i < s.length(); i++) {
      hash = (hash << 5) | (hash >>> 27);
      hash += (int) s.charAt(i);
    }
    return compress(hash);
  }

  // compress function
  static int compress(int h) {
    if (h < 0)
      h = -h;
    return h % table_size;
  }

  public static void main(String[] args) throws IOException
  {
    int h; // hash code

    FileReader fr = new FileReader(args[0]);
    BufferedReader reader = new BufferedReader(fr);
    Compare t1 = new Compare(Integer.parseInt(args[1]));
    Compare t2 = new Compare(Integer.parseInt(args[1]));
    Compare t3 = new Compare(Integer.parseInt(args[1]));
    Compare t4 = new Compare(Integer.parseInt(args[1]));
    Compare t5 = new Compare(Integer.parseInt(args[1]));

    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
      h = hash1(line);
      if (t1.hashTable[h] != null) t1.n++;
      else t1.hashTable[h] = line;
      t1.total++;

      h = hash2(line);
      if (t2.hashTable[h] != null) t2.n++;
      else t2.hashTable[h] = line;
      t2.total++;

      h = hash3(line);
      if (t3.hashTable[h] != null) t3.n++;
      else t3.hashTable[h] = line;
      t3.total++;

      h = hash4(line);
      if (t4.hashTable[h] != null) t4.n++;
      else t4.hashTable[h] = line;
      t4.total++;

      h = hash5(line);
      if (t5.hashTable[h] != null) t5.n++;
      else t5.hashTable[h] = line;
      t5.total++;
    }
    System.out.println("Total entries: " + t1.total);
    System.out.println("t1: (length) " + (float)(t1.n)/t1.total*100 + "% collisions");
    System.out.println("t2: (summing) " + (float)(t2.n)/t2.total*100 + "% collisions");
    System.out.println("t3: (partial hashing) " + (float)(t3.n)/t3.total*100 + "% collisions");
    System.out.println("t4: (hashing) " + (float)(t4.n)/t4.total*100 + "% collisions");
    System.out.println("t5: (shifting) " + (float)(t5.n)/t5.total*100 + "% collisions");
  }
}