s = list(map(int,list(eval(input()))))[::-1]

n = len(s)

chk = [0]*2019

chk[0] = 1

t,m,ans = 1,0,0

for i in s:

    m = (m+t*i)%2019

    ans += chk[m]

    chk[m] += 1

    t = t*10%2019

print(ans)

def main():

    S = eval(input())

    u = 0

    H = [0] * 2019

    H[0] = 1

    m = 1

    r = 0

    for s in reversed(S):

        u = (u + m * int(s)) % 2019

        r += H[u]

        H[u] += 1

        m = (m * 10) % 2019

    return r





print((main()))

s = list(map(int, list(eval(input()))))[::-1]
n = len(s)
chk = [0] * 2019
chk[0] = 1
t, m, ans = 1, 0, 0
for i in s:
    m = (m + t * i) % 2019
    ans += chk[m]
    chk[m] += 1
    t = t * 10 % 2019
print(ans)

def main():
    S = eval(input())
    u = 0
    H = [0] * 2019
    H[0] = 1
    m = 1
    r = 0
    for s in reversed(S):
        u = (u + m * int(s)) % 2019
        r += H[u]
        H[u] += 1
        m = (m * 10) % 2019
    return r


print((main()))

-s = list(map(int, list(eval(input()))))[::-1] -n = len(s) -chk = [0] * 2019 -chk[0] = 1 -t, m, ans = 1, 0, 0 -for i in s: -    m = (m + t * i) % 2019 -    ans += chk[m] -    chk[m] += 1 -    t = t * 10 % 2019 -print(ans) +def main(): +    S = eval(input()) +    u = 0 +    H = [0] * 2019 +    H[0] = 1 +    m = 1 +    r = 0 +    for s in reversed(S): +        u = (u + m * int(s)) % 2019 +        r += H[u] +        H[u] += 1 +        m = (m * 10) % 2019 +    return r + + +print((main()))