from collections import defaultdict

import numpy as np

def main():

    s = eval(input())

    n = len(s)

    d = np.zeros(2019,np.int64)

    ans = 0

    num = 0

    pow10 = 1

    d[0] = 1

    for i in reversed(list(range(n))):

        pow10 = pow10 * 10 % 2019

        num += int(s[i]) * pow10

        #print(num, num % 2019, i)

        mod = num % 2019

        ans += d[mod]

        d[mod] += 1

    print(ans)



if __name__ == "__main__":

    main()

from collections import defaultdict



def main():

    s = eval(input())

    n = len(s)

    ans = 0

    num = 0

    pow10 = 1

    d = defaultdict(int)

    d[0] = 1

    for i in reversed(list(range(n))):

        # pow10を10 ** (n-1-i)にしてるだけでTLEしていた

        pow10 = pow10 * 10 % 2019

        num += int(s[i]) * pow10

        mod = num % 2019

        ans += d[mod]

        d[mod] += 1

    print(ans)





if __name__ == "__main__":

    main()

from collections import defaultdict
import numpy as np


def main():
    s = eval(input())
    n = len(s)
    d = np.zeros(2019, np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(list(range(n))):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        # print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)


if __name__ == "__main__":
    main()

from collections import defaultdict


def main():
    s = eval(input())
    n = len(s)
    ans = 0
    num = 0
    pow10 = 1
    d = defaultdict(int)
    d[0] = 1
    for i in reversed(list(range(n))):
        # pow10を10 ** (n-1-i)にしてるだけでTLEしていた
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)


if __name__ == "__main__":
    main()

-import numpy as np -    d = np.zeros(2019, np.int64) +    d = defaultdict(int) +        # pow10を10 ** (n-1-i)にしてるだけでTLEしていた -        # print(num, num % 2019, i)