n = gets.to_i
s = gets.chomp.chars.map(&:to_i)
cnt = 0
array = Array.new(n){Array.new}
ans = Array.new(10){Array.new(10,-1)}
s.reverse_each.with_index do |c,i|
  if i != 0
    array[n-1 - i] = Array.new(array[n - i])
    array[n-1 - i] << c
    array[n-1 - i].uniq!
  else
    array[n-1 - i] << c
  end
end

(0..n-3).each do |i|
  (i+1..n-2).each do |j|
    if ans[s[i]][s[j]] == -1
      cnt += array[j+1].size
      ans[s[i]][s[j]] = 1
    end
  end
end

puts cnt