local m=(require(script.Parent.Parent.Parent.Llama)).List local function B(m)local B={m[1]}for D=2,#m,1 do if m[D-1]~=m[D]then B[#B+1]=m[D]end end return B end local function D(D)local X=B(m.sort(D,function(m,B)return m<B end))return setmetatable(X,{})end local X={}X.__add=function(m,B)local X=D({})local h=0 local Z=0 while h<#m or Z<#B do if h==#m then X[(h+Z)+1]=B[Z+1]Z=Z+1 elseif Z==#B then X[(h+Z)+1]=m[h+1]h=h+1 elseif m[h]<B[Z]then X[(h+Z)+1]=m[h+1]h=h+1 elseif m[h]==B[Z]then X[(h+Z)+1]=m[h+1]h=h+1 Z=Z+1 else X[(h+Z)+1]=B[Z+1]Z=Z+1 end end return X end X.__mul=function(m,B)local X=D({})if m==nil or B==nil or#m==0 or#B==0 then return X end local h=1 local Z=1 while h<=#m and Z<=#B do while h<=#m and(Z<=#B and m[h]<B[Z])do h=h+1 end while h<=#m and(Z<=#B and m[h]>B[Z])do Z=Z+1 end if m[h]==B[Z]then X[#X+1]=m[h]h=h+1 Z=Z+1 end end return X end X.__eq=function(m,B)if#m~=#B then return false end for D=1,#m,1 do if m[D]~=B[D]then return false end end return true end X.__lt=function(m,B)if#m>=#B then return false end return m*B==m end X.__le=function(m,B)return m*B==m end return{Set=X,new=D;removeDuplicatesFromSortedList=B}
local List = require(script.Parent.Parent.Parent.Llama).List

local function removeDuplicatesFromSortedList(array)
    local result = {array[1]}

    for i = 2, #array do
        if array[i - 1] ~= array[i] then
            result[#result+1] = array[i]
        end
    end

    return result
end

local function setFromArray(array) 
    local set = removeDuplicatesFromSortedList(List.sort(array, function(a, b) 
        return a < b 
    end))

    return setmetatable(set, {
        
    })
end

local Set = {}

Set.__add = function (left, right)
    local result = setFromArray({})

    local i = 0
    local j = 0

    while i < #left or j < #right do
        if i == #left then
            result[i + j + 1] = right[j + 1]
            j = j + 1
        elseif j == #right then
            result[i + j + 1] = left[i + 1]
            i = i + 1        
        elseif left[i] < right[j] then
            result[i + j + 1] = left[i + 1]
            i = i + 1
        elseif left[i] == right[j] then
            result[i + j + 1] = left[i + 1]
            i = i + 1
            j = j + 1
        else
            result[i + j + 1] = right[j + 1]
            j = j + 1
        end
    end

    return result
end

Set.__mul = function (left, right)
    local result = setFromArray({})

    if left == nil or right == nil or #left == 0 or #right == 0 then
        return result
    end

    local i = 1
    local j = 1

    while i <= #left and j <= #right do
        while i <= #left and j <= #right and left[i] < right[j] do
            i = i + 1
        end
        while i <= #left and j <= #right and left[i] > right[j] do
            j = j + 1
        end
        if left[i] == right[j] then
            result[#result+1] = left[i]
            i = i + 1
            j = j + 1
        end
    end

    return result
end

Set.__eq = function (left, right)
    if #left ~= #right then
        return false
    end

    for i = 1, #left do
        if left[i] ~= right[i] then
            return false
        end
    end

    return true
end

Set.__lt = function (left, right)
    if #left >= #right then
        return false
    end

    return left * right == left
end

Set.__le = function (left, right)
    return left * right == left
end



return {
    Set = Set,
    new = setFromArray,
    removeDuplicatesFromSortedList = removeDuplicatesFromSortedList
}