#!/usr/bin/env lua

local function contains(table, val)
    for i=1,#table do
        if table[i] == val then
            return true
        end
    end
    return false
end

local function some_calculations(number)
    local a = {}

    local x = 0
    for i=0, number-1 do
        x = x + i
        a[i] = i % 2 ~= 0 and -x or x
    end

    local tot = 0
    for i=0, number-1 do
        x = a[i]
        for i2 = i + 1, number-1 do
            local y = a[i2]
            local c = -(x + y)
            if c ~= x and c ~= y and contains(a, c) then
                tot = tot + 1
            end
        end
    end
    return tot
end

local sum = 0
for i=0, 499 do
    local calc = some_calculations(i)
    sum = sum + calc
end
print(tostring(sum))
