n = tonumber(io.read())
s = io.read()

t = {{}, {}, {}}

cnt = 0

for i = n, 1, -1 do
    cur = s:sub(i, i)
    for v in pairs(t[2]) do
        if not t[3][cur .. v] then cnt = cnt + 1 end
        t[3][cur .. v] = true
    end
    for v in pairs(t[1]) do
        t[2][cur .. v] = true
    end
    t[1][cur] = true
end

print(cnt)