import std.algorithm, std.array, std.range, std.stdio, std.string, std.conv;
void main()
{
    readln;
    auto buf = readln.chomp.split.to!(int[]);
    auto len = buf.sort.group.array;
    ulong sum = 0;
    foreach (i; 0..len.length)
        foreach (j; i..len.length)
        {
            auto inminLength = len[j][0] - len[i][0] + 1;
            debug inminLength.writeln;
            auto k = len.bs(0, len.length-1, inminLength);
            auto c = countValid(len, i, j, k);
            debug c.writeln;
            sum += c;
        }
    sum.writeln;
}

unittest
{
    auto arr = [[1, 1], [2, 1], [3, 1], [4, 1]];
    assert (arr.countValid(2, 3, 1) == 0);
}

auto countValid(T)(T len, size_t i, size_t j, size_t k)
{
    debug writefln!"%d %d %d"(i, k, j);
    if (k < i)
        k = i;
    if (k == j)
        return (len[k][1] < 2) ? 0 : 1;
    auto ret = j - k + 1;
    debug writeln(ret);
    if (i == k)
        if (len[k][1] == 1)
            ret -= 1;
    debug writeln(ret);
    if (len[j][1] == 1)
        ret -= 1;
    debug writeln(ret);
    return ret;
}

size_t bs(T)(T len, size_t i, size_t j, int t)
in
{
    assert (i <= j);
}
out (result)
{
    debug writefln!"%d(%d) %d"(result, len[result][0], t);
    assert (0 <= result);
    assert (result < len.length);
    assert (t <= len[result][0]);
    if (result)
        assert (len[result-1][0] < t);
}
body
{
    debug writefln!"%d(%d) %d %d(%d)"(i, len[i][0], t, j, len[j][0]);
    if (i == j)
        return i;
    if (i + 1 == j)
        if (len[i][0] < t)
            return j;
        else
            return i;
    auto m = (i + j) / 2;
    if (t < len[m][0])
        return len.bs(i, m, t);
    else
        return len.bs(m, j, t);
}
