ss = input()[::-1]
sv = ''
mods = {}

for s in ss:
    sv = s + sv
    i = int(sv) % 2019
    try:
        mods[i] += 1
    except KeyError:
        mods[i] = 1

if 0 in mods.keys():
    ans = 1
else:
    ans = 0

for v in mods.values():
    ans += (v * (v - 1)) // 2

print(ans)