repeat
   s$ = input
   until s$ = ""
   for n$ in strsplit s$ " "
      pok$[] &= n$
   .
.
# 
chain$[] = [ ]
proc search lng . .
   if lng > len chain$[]
      chain$[] = [ ]
      for j to lng
         chain$[] &= pok$[j]
      .
   .
   lastc$ = substr pok$[lng] len pok$[lng] 1
   for i = lng + 1 to len pok$[]
      if substr pok$[i] 1 1 = lastc$
         swap pok$[i] pok$[lng + 1]
         search lng + 1
         swap pok$[i] pok$[lng + 1]
      .
   .
.
for i to len pok$[]
   swap pok$[i] pok$[1]
   search 1
   swap pok$[i] pok$[1]
.
for p$ in chain$[]
   write p$ & " "
.
# 
input_data
audino bagon baltoy banette bidoof braviary bronzor carracosta charmeleon
cresselia croagunk darmanitan deino emboar emolga exeggcute gabite
girafarig gulpin haxorus heatmor heatran ivysaur jellicent jumpluff kangaskhan
kricketune landorus ledyba loudred lumineon lunatone machamp magnezone mamoswine
nosepass petilil pidgeotto pikachu pinsir poliwrath poochyena porygon2
porygonz registeel relicanth remoraid rufflet sableye scolipede scrafty seaking
sealeo silcoon simisear snivy snorlax spoink starly tirtouga trapinch treecko
tyrogue vigoroth vulpix wailord wartortle whismur wingull yamask
