-- A function that drops the first n eleements of list
function Drop(list,n)
    local result = {}
    for i = n +1, #list do
        result[i-n] = list[i]
    end
    return result
end

-- A function that takes eleements n1 to n2 of list
function Take(list,n1,n2)
  local result={}
  if n2== nil then
    if n1 > 0 then
      for i = 1, n1 do
        result[i]=list[i]
      end
    else
      for i=1,-n1 do
        result[i]=list[#list+n1+i]
      end
    end
   else
     for i = n1, n2 do
       result[i+1-n1] = list[i]
     end
   end
  return result
end

-- A function that joins lists
function Join(...)
  local result = {}
  local n=1
  for i = 1, select("#",...) do
    for j=1,#select(i,...) do
      result[n]=select(i,...)[j]
      n=n+1
    end
  end
  return result
end

-- A function that flattens nested lists by one level
function Flatten(list)
  local result = {}
  local k=1
  for i=1,#list do
    for j=1,#list[i] do
      result[k] = list[i][j]
      k=k+1
    end
  end
  return result
end

-- A function that checks whether x is contained in list M
function IsElement(x, M)
    for i = 1, #M do
        if M[i] == x then return true end
    end
    return false
end
