import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

import numpy as np

from numba import njit



@njit('(i4[:],)')

def solve(S):

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

    pow10 = 1

    answer = 0

    for x in S[::-1]:

        dp[0] += 1

        x = x * pow10 % 2019

        newdp = np.zeros_like(dp)

        newdp[x:] += dp[:-x]

        newdp[:x] += dp[-x:]

        answer += newdp[0]

        pow10 *= 10

        pow10 %= 2019

        dp = newdp

    return answer





S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')

print((solve(S)))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

import numpy as np

from numba import njit



@njit('(i4[:],)', cache=True)

def solve(S):

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

    pow10 = 1

    answer = 0

    for x in S[::-1]:

        dp[0] += 1

        x = x * pow10 % 2019

        newdp = np.zeros_like(dp)

        newdp[x:] += dp[:-x]

        newdp[:x] += dp[-x:]

        answer += newdp[0]

        pow10 *= 10

        pow10 %= 2019

        dp = newdp

    return answer





S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')

print((solve(S)))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit


@njit("(i4[:],)")
def solve(S):
    dp = np.zeros(2019, np.int64)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = np.zeros_like(dp)
        newdp[x:] += dp[:-x]
        newdp[:x] += dp[-x:]
        answer += newdp[0]
        pow10 *= 10
        pow10 %= 2019
        dp = newdp
    return answer


S = np.array(list(read().rstrip()), dtype=np.int32) - ord("0")
print((solve(S)))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit


@njit("(i4[:],)", cache=True)
def solve(S):
    dp = np.zeros(2019, np.int64)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = np.zeros_like(dp)
        newdp[x:] += dp[:-x]
        newdp[:x] += dp[-x:]
        answer += newdp[0]
        pow10 *= 10
        pow10 %= 2019
        dp = newdp
    return answer


S = np.array(list(read().rstrip()), dtype=np.int32) - ord("0")
print((solve(S)))

-@njit("(i4[:],)") +@njit("(i4[:],)", cache=True)