import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

from collections import defaultdict

def main():

    s = tuple(map(int, eval(input())))

    lens = len(s)



    d1 = defaultdict(int)

    ss = 0

    k = 1

    num10 = 1

    while k <= lens:

        ss += (int(s[-k]) * num10) % 2019

        ss = ss % 2019

        d1[ss] += 1

        k += 1

        num10 = (num10 * 10) % 2019

    r = d1[0]

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

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

    print(r)



if __name__ == '__main__':

    main()
import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

from collections import defaultdict

def main():

    s = tuple(map(int, eval(input())))

    lens = len(s)



    d1 = defaultdict(int)

    ss = 0

    num10 = 1

    for i1 in range(1, lens+1):

        ss += (int(s[-i1]) * num10) % 2019

        ss = ss % 2019

        d1[ss] += 1

        num10 = (num10 * 10) % 2019

    r = d1[0]

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

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

    print(r)



if __name__ == '__main__':

    main()
import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict


def main():
    s = tuple(map(int, eval(input())))
    lens = len(s)
    d1 = defaultdict(int)
    ss = 0
    k = 1
    num10 = 1
    while k <= lens:
        ss += (int(s[-k]) * num10) % 2019
        ss = ss % 2019
        d1[ss] += 1
        k += 1
        num10 = (num10 * 10) % 2019
    r = d1[0]
    for v in list(d1.values()):
        r += v * (v - 1) // 2
    print(r)


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict


def main():
    s = tuple(map(int, eval(input())))
    lens = len(s)
    d1 = defaultdict(int)
    ss = 0
    num10 = 1
    for i1 in range(1, lens + 1):
        ss += (int(s[-i1]) * num10) % 2019
        ss = ss % 2019
        d1[ss] += 1
        num10 = (num10 * 10) % 2019
    r = d1[0]
    for v in list(d1.values()):
        r += v * (v - 1) // 2
    print(r)


if __name__ == "__main__":
    main()

-    k = 1 -    while k <= lens: -        ss += (int(s[-k]) * num10) % 2019 +    for i1 in range(1, lens + 1): +        ss += (int(s[-i1]) * num10) % 2019 -        k += 1