local str = io.read() local t = {} local function cww(i, j, k) ret = 0 if(0 <= t[i] and 0 <= t[j] and 0 <= t[k]) then if(t[i] ~= t[j] and t[j] == t[k]) then ret = t[i] * 100 + t[j] * 11 end end return ret end local box = {} for i = 1, 12 do box[i] = false end local function setbox(i, j, k, flag) box[i], box[j], box[k] = flag, flag, flag end local function getbox(idx) local i = 1 for j = 1, 12 do if(not box[j]) then if(i == idx) then return j else i = i + 1 end end end return nil end if(str == "1000000000000") then print(100) else for i = 1, 12 do if(#str < i) then t[i] = -1 else t[i] = tonumber(str:sub(i, i)) end end local cwwmax = 0 for i1=1,10 do for j1=i1+1,11 do for k1=j1+1,12 do setbox(i1, j1, k1, true) for i2=1,7 do for j2=i2+1,8 do for k2=j2+1,9 do local i2r, j2r, k2r = getbox(i2), getbox(j2), getbox(k2) setbox(i2r, j2r, k2r, true) for i3=1,4 do for j3=i3+1,5 do for k3=j3+1,6 do local i3r, j3r, k3r = getbox(i3), getbox(j3), getbox(k3) setbox(i3r, j3r, k3r, true) local i4r, j4r, k4r = getbox(1), getbox(2), getbox(3) cwwmax = math.max(cwwmax, cww(i1,j1,k1)+cww(i2r,j2r,k2r)+cww(i3r,j3r,k3r)+cww(i4r,j4r,k4r)) setbox(i3r, j3r, k3r, false) end end end setbox(i2r, j2r, k2r, false) end end end setbox(i1, j1, k1, false) end end end print(cwwmax) end