Problem:
Problem Statement

We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins.
After analysis of the dictionary, we revealed they used a language that had not more than 26 letters.
So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary into a computer.

How the words are ordered in the dictionary, especially whether they are ordered lexicographically, is an interesting topic to many people.
As a good programmer, you are requested to write a program to judge whether we can consider the words to be sorted in a lexicographical order.

Note:
In a lexicographical order, a word always precedes other words it is a prefix of.
For example, ab
precedes abc,
abde, and so on.

Input

The input consists of multiple datasets. Each dataset is formatted as follows:

n
string_1
...
string_n

Each dataset consists of n+1 lines.
The first line of each dataset contains an integer that indicates n (1 \leq n \leq 500).
The i-th line of the following n lines contains string_i, which consists of up to 10 English lowercase letters.

The end of the input is 0, and this should not be processed.

Output

Print either yes or
no in a line for each dataset, in the order of the input.
If all words in the dataset can be considered to be ordered lexicographically, print yes.
Otherwise, print no.

Sample Input

4
cba
cab
b
a
3
bca
ab
a
5
abc
acb
b
c
c
5
abc
acb
c
b
b
0

Output for the Sample Input

yes
no
yes
no

Solution in Ruby (judge verdict: Wrong Answer)

# Header {{{

def assert(p)
  raise 'Assertion Failed' unless p
end

# Requires {{{
require 'set'
# }}}

# Constants {{{
INF = 10**9
# }}}

# IO {{{
class MyIO
  def initialize
    @input = $stdin
    @output = $stdout
  end

  # @param filename [String]
  def set_input(filename)
    @input = File.open(filename, 'r')
  end

  def set_output(filename)
    @output = File.open(filename, 'w')
  end

  def int
    gets.to_i
  end

  def ints
    split.map(&:to_i)
  end

  def split
    @input.gets.chomp.split(' ')
  end
  alias_method :strings, :split

  def gets
    @input.gets.chomp
  end

  def puts(*args)
    @output.puts(*args)
  end
end

io = MyIO.new
# }}}

# Algorithms {{{

def lower_bound(arr, val)
  assert(arr.is_a?(Array))
  low, high = 0, arr.size
  while high - low > 1
    mid = (low + high) / 2
    if arr[mid] < val
      low = mid
    else
      high = mid
    end
  end
  if arr[low] >= val
    low
  else
    high
  end
end

def upper_bound(arr, val)
  assert(arr.is_a?(Array))
  low, high = 0, arr.size
  while high - low > 1
    mid = (low + high) / 2
    if arr[mid] <= val
      low = mid
    else
      high = mid
    end
  end
  if arr[low] > val
    low
  else
    high
  end
end

# }}}

# }}}

# io.set_input('inputs/0.txt')

while true
  n = io.int
  break if n == 0
  bigger_chars = Hash.new { |h, k| h[k] = Set.new }
  prev_word = ''
  ok = true
  n.times do |i|
    word = io.gets
    [prev_word.length, word.length].min.times do |j|
      if prev_word[j] == word[j]
        next
      elsif bigger_chars[word[j]].include?(prev_word[j])
        ok = false and break
      else
        bigger_chars[prev_word[j]] << word[j]
        break
      end
    end
    if prev_word.start_with?(word) && prev_word != word
      ok = false
    end
    prev_word = word
  end
  puts ok ? 'yes' : 'no'
end

# vim: foldmethod=marker