# -*- coding: utf-8 -*-
S = str(input())

len_str = len(S)
dp_list = [-1 for _ in range(len_str)]

ans = 0
for i in range(len_str):
    for j in range(i + 4, len_str + 1):
        temp_ans = int(S[i:j]) if i == 0 or j == i + 4 else (dp_list[j - 2] * 10 + int(S[j - 1]))
        temp_ans %= 2019
        dp_list[j - 1] = temp_ans
        if temp_ans == 0:
            ans += 1
print(ans)