local str = io.read() local allsame, allsame2 = true, true local all480 = true local alleven = true local all50 = true local allmod7same = true local sum = 0 local first = tonumber(str:sub(1, 1)) local n = #str local t = {} local min = 9 local mmi, mfl = math.min, math.floor for i = 1, n do local a = tonumber(str:sub(i, i)) t[i] = a if a ~= 0 then min = mmi(min, a) end if a ~= first then allsame = false end end for i = 1, n do if t[i] % min ~= 0 then allsame2 = false break end end local ret = 1 if allsame2 then ret = min for i = 1, n do t[i] = mfl(t[i] / min) end end for i = 1, n do local a = t[i] if a % 7 ~= first % 7 then allmod7same = false end sum = sum + a end if allsame then print(str) else if sum % 9 == 0 then ret = ret * 9 elseif sum % 3 == 0 then ret = ret * 3 end if allmod7same and (n % 6 == 0) then ret = ret * 7 end print(ret) end