#!/usr/bin/env python3

from collections import Counter



def main():

    S = eval(input())

    N = len(S)

    T = [0] * (N+1)

    

    for i in range(N-1,-1,-1):

        T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019

    l = Counter(T)

    ans = 0

    for v in list(l.values()):

        ans += v * (v-1) // 2

    print(ans)



if __name__ == "__main__":

    main()

from collections import Counter



S = eval(input())

N = len(S)

mod = [0] * (N+1)

now = 0

for i in range(N):

    now += int(S[N-1-i]) * pow(10,i,2019) % 2019

    now %= 2019

    mod[N-i-1] = now



ans = 0

for l in list(Counter(mod).values()):

    ans += l * (l-1) // 2

print(ans)
#!/usr/bin/env python3
from collections import Counter


def main():
    S = eval(input())
    N = len(S)
    T = [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        T[i] = (T[i + 1] + int(S[i]) * pow(10, N - i, 2019)) % 2019
    l = Counter(T)
    ans = 0
    for v in list(l.values()):
        ans += v * (v - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

from collections import Counter

S = eval(input())
N = len(S)
mod = [0] * (N + 1)
now = 0
for i in range(N):
    now += int(S[N - 1 - i]) * pow(10, i, 2019) % 2019
    now %= 2019
    mod[N - i - 1] = now
ans = 0
for l in list(Counter(mod).values()):
    ans += l * (l - 1) // 2
print(ans)

-#!/usr/bin/env python3 - -def main(): -    S = eval(input()) -    N = len(S) -    T = [0] * (N + 1) -    for i in range(N - 1, -1, -1): -        T[i] = (T[i + 1] + int(S[i]) * pow(10, N - i, 2019)) % 2019 -    l = Counter(T) -    ans = 0 -    for v in list(l.values()): -        ans += v * (v - 1) // 2 -    print(ans) - - -if __name__ == "__main__": -    main() +S = eval(input()) +N = len(S) +mod = [0] * (N + 1) +now = 0 +for i in range(N): +    now += int(S[N - 1 - i]) * pow(10, i, 2019) % 2019 +    now %= 2019 +    mod[N - i - 1] = now +ans = 0 +for l in list(Counter(mod).values()): +    ans += l * (l - 1) // 2 +print(ans)