local lines = {} for line in io.lines() do table.insert(lines,line) end local sum = 0 for i = 1,#lines,3 do local l1,l2 = lines[i], lines[i+1] l1 = l1:gsub("%[","{"):gsub("]","}") l2 = l2:gsub("%[","{"):gsub("]","}") l1 = load("return "..l1)() l2 = load("return "..l2)() local function compare(a,b) -- return true if a comes before b assert(a ~= nil) assert(b ~= nil) if type(a) == "number" and type(b) == "number" then if a < b then return true elseif a > b then return false else return nil end elseif type(a) == "table" and type(b) == "table" then for i = 1,math.min(#a,#b) do local result = compare(a[i],b[i]) if result ~= nil then return result end end if #a < #b then return true elseif #a > #b then return false else return nil end elseif type(a) == "number" and type(b) == "table" then return compare({a},b) elseif type(a) == "table" and type(b) == "number" then return compare(a,{b}) end end if compare(l1,l2) then sum = sum + ((i+2)/3) end end print(sum)