-- "w" = 130 151 local a = "w" local wlen = #a local at = {} for i = 1, wlen do at[i] = a:sub(i, i):byte() end local str = io.read() local t = {} for i = 1, #str do t[i] = str:sub(i, i):byte() end local chain = 0 local stpos, edpos = 1 local i = 1 local wlist = {} local maxchain = 0 while(i <= #str + 1 - wlen) do local isw = true for j = 0, wlen - 1 do if(t[i + j] ~= at[1 + j]) then isw = false break end end if(isw) then if(chain == 0) then edpos = i - 1 end chain = chain + 1 i = i + wlen else if(0 < chain) then local len = edpos - stpos + 1 if(0 < len) then maxchain = math.max(chain, chain) if(wlist[chain] == nil) then wlist[chain] = {} end local tmp = {} tmp.st = stpos tmp.ed = edpos table.insert(wlist[chain], tmp) end stpos = i chain = 0 end i = i + 1 end end if(0 < chain) then local len = edpos - stpos + 1 if(0 < len) then maxchain = math.max(chain, chain) if(wlist[chain] == nil) then wlist[chain] = {} end local tmp = {} tmp.st = stpos tmp.ed = edpos table.insert(wlist[chain], tmp) end end if(maxchain == 0) then print("") else for k, v in pairs(wlist[maxchain]) do print(str:sub(v.st, v.ed)) end end