import numpy as np

from numba import njit



S = eval(input())

MOD = 2019

dp = np.zeros(MOD, dtype=np.int64)

dp[0] = 1



@njit

def hoge(dp, s):

    T = dp.copy()

    dp[s:] = T[:-s]

    dp[:s] = T[-s:]



ans = 0

for i, s in enumerate(S[::-1]):

    hoge(dp, (int(s) * pow(10, i, MOD)) % MOD)

    ans += dp[0]

    dp[0] += 1

print(ans)

import numpy as np



S = eval(input())

MOD = 2019

dp = np.zeros(MOD, dtype=np.int64)

dp[0] = 1



def hoge(dp, s):

    T = dp.copy()

    dp[s:] = T[:-s]

    dp[:s] = T[-s:]



ans = 0

for i, s in enumerate(S[::-1]):

    hoge(dp, (int(s) * pow(10, i, MOD)) % MOD)

    ans += dp[0]

    dp[0] += 1

print(ans)

import numpy as np
from numba import njit

S = eval(input())
MOD = 2019
dp = np.zeros(MOD, dtype=np.int64)
dp[0] = 1


@njit
def hoge(dp, s):
    T = dp.copy()
    dp[s:] = T[:-s]
    dp[:s] = T[-s:]


ans = 0
for i, s in enumerate(S[::-1]):
    hoge(dp, (int(s) * pow(10, i, MOD)) % MOD)
    ans += dp[0]
    dp[0] += 1
print(ans)

import numpy as np

S = eval(input())
MOD = 2019
dp = np.zeros(MOD, dtype=np.int64)
dp[0] = 1


def hoge(dp, s):
    T = dp.copy()
    dp[s:] = T[:-s]
    dp[:s] = T[-s:]


ans = 0
for i, s in enumerate(S[::-1]):
    hoge(dp, (int(s) * pow(10, i, MOD)) % MOD)
    ans += dp[0]
    dp[0] += 1
print(ans)

-from numba import njit -@njit