local str = io.read() local t = {} for i = 1, 9 do t[i] = 0 end for i = 1, 13 do local a = tonumber(str:sub(i, i)) t[a] = t[a] + 1 end local function agaricore(tbl, tp) local tblcpy = {unpack(tbl)} for i = 1, 4 do local curmin = 9 for j = 1, 9 do if 0 < tblcpy[j] then curmin = j break end end if tp[i] == 1 then if tblcpy[curmin] <= 2 then return false else tblcpy[curmin] = tblcpy[curmin] - 3 end else if 8 <= curmin then return false elseif tblcpy[curmin] == 0 or tblcpy[curmin + 1] == 0 or tblcpy[curmin + 2] == 0 then return false else tblcpy[curmin] = tblcpy[curmin] - 1 tblcpy[curmin + 1] = tblcpy[curmin + 1] - 1 tblcpy[curmin + 2] = tblcpy[curmin + 2] - 1 end end end return true end local function agari(tbl) -- chiitoi local chiitoi = 0 for i = 1, 9 do if tbl[i] == 2 then chiitoi = chiitoi + 1 end end if chiitoi == 7 then return true end for i_atama = 1, 9 do if 2 <= tbl[i_atama] then tbl[i_atama] = tbl[i_atama] - 2 -- print(unpack(tbl)) for c = 0, 15 do local tp = {} local tc = c for i = 1, 4 do table.insert(tp, tc % 2) tc = math.floor(tc / 2) end local ret = agaricore(tbl, tp) if ret then tbl[i_atama] = tbl[i_atama] + 2 return true end end tbl[i_atama] = tbl[i_atama] + 2 end end return false end for i = 1, 9 do -- print("--" .. i .. "--") if t[i] <= 3 then t[i] = t[i] + 1 -- print(unpack(t)) -- print("--") if agari(t) then print(i) end t[i] = t[i] - 1 end end