This page is still under construction.

Parts of this page are still being built. What you see may change.

Heavy Chain Clusterization

Time limit2sMemory limit256 MB

Summary
Split n antibody chains into the fewest groups so each group shares the same first k or last k letters.
Level

Medium7 of 10

Topics
Graph, String
Solved
No attempts yet

Problem

A group of biologists is looking for a cure for a viral disease. They tested many antibodies of different origins against the viral antigens and kept the nn antibodies that worked best in their experiments.

Every antibody is identified by its heavy chain, a sequence of amino acids. One amino acid is written as one uppercase English letter.

A set of antibodies is a similarity cluster when at least one of the following holds:

  • the kk-prefixes (the first kk amino acids) of all their heavy chains are equal;
  • the kk-suffixes (the last kk amino acids) of all their heavy chains are equal.

A set that holds a single antibody is always a similarity cluster.

To make the later research simpler, the biologists want to split the nn antibodies into similarity clusters, and every antibody has to belong to exactly one cluster. Find how few clusters are enough.

Input

The first line contains two integers nn and kk, the number of heavy chains and the length of the amino acid sequence that has to coincide (1≤n≤50001 \le n \le 5000, 1≤k≤5501 \le k \le 550).

Each of the next nn lines contains the heavy chain of one antibody. Every amino acid is an uppercase English letter, and every heavy chain has at least kk and at most 550550 amino acids.

Output

Print one integer, the minimum number of similarity clusters the nn antibodies can be split into.

Examples2

  1. Example 1

    Input
    4 1
    AA
    AB
    BB
    BA
    
    Expected output
    2
    
  2. Example 2

    Input
    3 2
    ABA
    BAB
    XY
    
    Expected output
    3