In this problem we are concerned with words constructed using the lowercase letters of the English alphabet - that is, a,b,c,…,z. These words need not necessarily be meaningful: any sequence of letters forms a word. For example, abbca is a word.
We say that we can "hop" from the word $w_1$ to the word $w_2$ if they are "sufficiently close". We define $w_2$ to be sufficiently close to $w_1$ if one of the following holds:
- $w_2$ is obtained from $w_1$ by deleting one letter.
- $w_2$ is obtained from $w_1$ by replacing one of the letters in $w_1$ by some letter that appears to its right in $w_1$ and which is also to its right in alphabetical order.
For example, we can hop from abbca to abca by deleting the second (or third letter). We can hop from aabca to abbca by replacing the a in the second position by the letter b that appears to the right of the a in aabca and which is also to its right in alphabetical order. On the other hand we cannot hop from abbca to aabca since we would need to replace the b in the second position by a, but a is to the left of b in alphabetical order.
You will be given a collection of words $W$. Your task is to find the length of the longest sequence $w_1, w_2, \ldots $ of distinct words from $W$ such that we may hop from $w_1$ to $w_2$, $w_2$ to $w_3$ and so on. We call this the hopping number for this set.
For example, if
$W$ = {abacd, bcdada, dd, abcd,bcdd, adcd, addd, aa, ccd, add, ad}
then, the hopping number is 7 corresponding to the sequence
abacd, abcd, adcd, addd, add, ad, dd

-----Input Format:-----
- The first line of the input contains one integer $N$ indicating the number of words in the input. 
- This is followed by $N$ lines of input, lines 2, 3,…, $N$+1, each containing one word over the letters {a,b,…, z}.

-----Output Format:-----
The output should be a single integer, indicating the hopping number of the given set of words.

-----Test Data:-----
- $N \leq 100$
- You may assume that each word has at most 10 letters.

-----Sample Input:-----
11
abacd
bcdada
dd
abcd
bcdd
adcd
addd
aa
ccd
add
ad

-----Sample Output:-----
7

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def codn1(s1,s2,p):\r\n\tc=0\r\n\tind=0\r\n\tfor i in range(len(s1)):\r\n\t\tif s1[i]!=s2[i]:\r\n\t\t\tc+=1\r\n\t\t\tind=i\r\n\tif c>1 or ind==len(s1)-1:\r\n\t\treturn 0\r\n\tif s1[ind]>s2[ind] and s1[ind] in s2[ind+1:]:\r\n\t\tp[0]=True\r\n\tif s1[ind]<s2[ind] and s2[ind] in s1[ind+1:]:\r\n\t\tp[1]=True\r\n\treturn 1\r\n\t\r\ndef codn2(s1,s2):\r\n\tif len(s1)<len(s2):\r\n\t\tfor i in range(len(s2)):\r\n\t\t\tif s2[:i]+s2[i+1:]==s1:\r\n\t\t\t\treturn 1\r\n\telse:\r\n\t\tfor i in range(len(s1)):\r\n\t\t\tif s1[:i]+s1[i+1:]==s2:\r\n\t\t\t\treturn 2\r\n\r\n\r\ndef longest(k):\r\n\tif cost[k]>0:\r\n\t\treturn cost[k]\r\n\tfor i in list(d[k]):\r\n\t\t\tcost[k]=max(cost[k],longest(i)+1)\r\n\treturn cost[k]\r\n\r\nn=int(input())\r\nl=[]\r\n#parent=[0]*n\r\nd={}\r\ncost={}\r\nfor i in range(n):\r\n\tl.append(input())\r\n\td[i]=[]\r\n\tcost[i]=0\r\n\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif i!=j:\r\n\t\t\tp=[False,False]\r\n\t\t\tif len(l[i])==len(l[j]):\r\n\t\t\t\tif codn1(l[i],l[j],p):\r\n\t\t\t\t\tif p[0]==True:\r\n\t\t\t\t\t\td[j].append(i)\r\n\t\t\t\t\tif p[1]==True:\r\n\t\t\t\t\t\td[i].append(j)\r\n\t\t\telif abs(len(l[i])-len(l[j]))==1:\r\n\t\t\t\ty=codn2(l[i],l[j])\r\n\t\t\t\tif y==1:\r\n\t\t\t\t\td[j].append(i)\r\n\t\t\t\tif y==2:\r\n\t\t\t\t\td[i].append(j)\r\nans=0\r\n#print(d)\r\n\r\nfor i in range(n):\r\n\tans=max(ans,longest(i))\r\nprint(ans+1)\r\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14121