#!/usr/bin/env python3
import sys


def solve(S: int):
    S =str(S)
    l = len(S)
    elds = [x*2019 for x in range(10000) if "0" not in str(x*2019)]
    # print(elds)
    s = S
    ans = []
    prev = -1
    for t in range(5,9):
        for x in range(l-t+1):
            # print(s[x:x+t])           
            if int(s[x:x+t]) in elds:
                ans.append((x,x+t))

    p= [a_[0] for a_ in ans]
    q= [a_[1] for a_ in ans]
    t = set(p)&set(q)
    ad = 0
    for t_ in t:
        ad+=p.count(t_)
        ad+=q.count(t_)

    print(len(ans)+ad//2)
    

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()
