Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
 
 
l = [0] * 2019
index = 0
temp = 0
for i in range(N-1, -1, -1):
    temp += int(S[i]) * 10**index
    l[temp%2019] += 1
    index += 1
 
ans = l[0]
 
for i in range(1, 2019):
    v = l[i]
    ans += v * (v-1) // 2
 
print(ans)

Fixed submission:
S = list(input())
N = len(S)
S = [int(s) for s in S]
S = S[::-1]
l = [0] * 2019
index = 0
tmp = 0
z = 1
for i, s in enumerate(S):
    tmp += s * pow(10, i, 2019)
    l[tmp%2019] += 1

ans = l[0]

for v in l:
    ans += v * (v-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
 
 
l = [0] * 2019
index = 0
temp = 0
for i in range(N-1, -1, -1):
    temp += int(S[i]) * 10**index
    l[temp%2019] += 1
    index += 1
 
ans = l[0]
 
for i in range(1, 2019):
    ans += l[i] * (l[i]-1) // 2
 
print(ans)

Fixed submission:
S = list(input())
N = len(S)
S = [int(s) for s in S]
S = S[::-1]
l = [0] * 2019
index = 0
tmp = 0
z = 1
for i, s in enumerate(S):
    tmp += s * pow(10, i, 2019)
    l[tmp%2019] += 1

ans = l[0]

for v in l:
    ans += v * (v-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
# I = INT()
I = int(S)
N = len(S)
left = 0
l = []
dp = [0] * (N + 1)
ans = 0
for right in range(N):
    for left in range(right):
        # if left < right:
        # l.append(S[right])
        # s_str = "".join(l)
        s_str = S[left:right+1]
        tmp = int(s_str)
        # print(tmp)
        if tmp % 2019 == 0:
            # print(tmp // 2019)
            # print(tmp)
            # dp[right] += 1
            ans += 1
print(ans)
    





exit()
L = len(n)
K = 10
# dp[i][j][k]
# j その地点で持っている2019の数
#
dp = [[[0] * 2 for i in range(K)] for i in range(L+1)]
# K+1のところKにした

dp[0][0][0] = 1

for i in range(L):
    for j in range(1, K):
        for k in range(2):
            nd = int(n[i])
            for d in range(1, 10):
                ni = i + 1
                nj = j
                nk = k
                
                if d == 1:
                    nj += 1
                # 10 ** 9 より大きくなることはない
                if nj > 9:
                    continue
                #    
                if k == 0:
                    if d == nd:
                        nk = 0
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1

                dp[ni][nj][nk] += dp[i][j][k]
# ans = dp[L][K][0] + dp[L][K][1]

print(dp)
# ans = 0
# # iをかけた(?)
# for i in range(1, 10):
#     ans += i * (dp[L][i][0] + dp[L][i][1])
# # print(dp)
# print(ans)



Fixed submission:
S = list(input())
N = len(S)
S = [int(s) for s in S]
S = S[::-1]
l = [0] * 2019
index = 0
tmp = 0
z = 1
for i, s in enumerate(S):
    tmp += s * pow(10, i, 2019)
    l[tmp%2019] += 1

ans = l[0]

for v in l:
    ans += v * (v-1) // 2
print(ans)