s = input()
n = len(s)

def make_z_list(s):
    n = len(s)

    z_list = [0] * n
    z_list[0] = n
    
    i = 1
    j = 0
    
    while i < n:
        while i + j < n and s[j] == s[i + j]:
            j += 1
    
        z_list[i] = j
        
        if j == 0:
            i += 1
            continue
    
        k = 1
        while i + k < n and k + z_list[k] < j:
            z_list[i + k] = z_list[k]
            k += 1
    
        i += k
        j -= k
    
    return z_list

ans = 0
for i in range(n):
    z_list = make_z_list(s[i:])
    for z in z_list:
        # print(s[i:i+z])
        if z >= 4 and int(s[i:i+z]) % 2019 == 0:
            ans += 1
print(ans)