import numpy as np

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

n = len(s)

ans = 0

mod = 2019

past = s[n-1]

ima = 0

d = dict()

d[s[n-1]] = 1

now = 10

for i in range(1,n):

    ima = (past+s[n-i-1]*now)%mod

    if ima == 0:

        ans += 1

    if ima in d:

        d[ima] += 1

    else:

        d[ima] = 1

    past = ima

    now = (now*10)%mod



for i in list(d.values()):

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



print(ans)

import math

#import numpy as np

import queue

from collections import deque,defaultdict

import heapq

from sys import stdin,setrecursionlimit

#from scipy.sparse.csgraph import dijkstra

#from scipy.sparse import csr_matrix

ipt = stdin.readline

setrecursionlimit(10**7)



def main():

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

    d = defaultdict(int)

    ans = 0

    ni = 0

    mod = 2019

    d[0] = 1

    n10 = 1

    for i in s:

        ni = (ni+i*n10)%mod

        d[ni] += 1

        n10 = (n10*10)%mod

    for i in list(d.values()):

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

    print(ans)



    return



if __name__ == '__main__':

    main()

import numpy as np

s = list(map(int, eval(input())))
n = len(s)
ans = 0
mod = 2019
past = s[n - 1]
ima = 0
d = dict()
d[s[n - 1]] = 1
now = 10
for i in range(1, n):
    ima = (past + s[n - i - 1] * now) % mod
    if ima == 0:
        ans += 1
    if ima in d:
        d[ima] += 1
    else:
        d[ima] = 1
    past = ima
    now = (now * 10) % mod
for i in list(d.values()):
    ans += i * (i - 1) // 2
print(ans)

import math

# import numpy as np
import queue
from collections import deque, defaultdict
import heapq
from sys import stdin, setrecursionlimit

# from scipy.sparse.csgraph import dijkstra
# from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)


def main():
    s = list(map(int, eval(input())))[::-1]
    d = defaultdict(int)
    ans = 0
    ni = 0
    mod = 2019
    d[0] = 1
    n10 = 1
    for i in s:
        ni = (ni + i * n10) % mod
        d[ni] += 1
        n10 = (n10 * 10) % mod
    for i in list(d.values()):
        ans += i * (i - 1) // 2
    print(ans)
    return


if __name__ == "__main__":
    main()

-import numpy as np +import math -s = list(map(int, eval(input()))) -n = len(s) -ans = 0 -mod = 2019 -past = s[n - 1] -ima = 0 -d = dict() -d[s[n - 1]] = 1 -now = 10 -for i in range(1, n): -    ima = (past + s[n - i - 1] * now) % mod -    if ima == 0: -        ans += 1 -    if ima in d: -        d[ima] += 1 -    else: -        d[ima] = 1 -    past = ima -    now = (now * 10) % mod -for i in list(d.values()): -    ans += i * (i - 1) // 2 -print(ans) +# import numpy as np +import queue +from collections import deque, defaultdict +import heapq +from sys import stdin, setrecursionlimit + +# from scipy.sparse.csgraph import dijkstra +# from scipy.sparse import csr_matrix +ipt = stdin.readline +setrecursionlimit(10**7) + + +def main(): +    s = list(map(int, eval(input())))[::-1] +    d = defaultdict(int) +    ans = 0 +    ni = 0 +    mod = 2019 +    d[0] = 1 +    n10 = 1 +    for i in s: +        ni = (ni + i * n10) % mod +        d[ni] += 1 +        n10 = (n10 * 10) % mod +    for i in list(d.values()): +        ans += i * (i - 1) // 2 +    print(ans) +    return + + +if __name__ == "__main__": +    main()