n = int(input()) s = input() ret = 0 last0 = 0 for i, c in enumerate(s): if c == '0': ret += (i - last0) * (n - i) last0 = i print(ret)