def main():

  n, mods = 0, [1]+[0]*2019

  d = 1

  for j in map(int, input()[::-1]):

    n = (n+int(j)*d)%2019

    d = d*10%2019

    mods[n] += 1

  print((sum([i*(i-1)//2 for i in mods])))

main()
def main():

  n, mods = 0, [1]+[0]*2019

  d = 1

  for i in reversed(eval(input())):

    n = (n+int(i)*d)%2019

    d = d*10%2019

    mods[n] += 1

  print((sum([i*(i-1)//2 for i in mods])))

main()
def main():
    n, mods = 0, [1] + [0] * 2019
    d = 1
    for j in map(int, input()[::-1]):
        n = (n + int(j) * d) % 2019
        d = d * 10 % 2019
        mods[n] += 1
    print((sum([i * (i - 1) // 2 for i in mods])))


main()

def main():
    n, mods = 0, [1] + [0] * 2019
    d = 1
    for i in reversed(eval(input())):
        n = (n + int(i) * d) % 2019
        d = d * 10 % 2019
        mods[n] += 1
    print((sum([i * (i - 1) // 2 for i in mods])))


main()

-    for j in map(int, input()[::-1]): -        n = (n + int(j) * d) % 2019 +    for i in reversed(eval(input())): +        n = (n + int(i) * d) % 2019