Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta *= 10


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = str(input())
N = len(S)

smod = [int(S[i:])%2019 for i in range(N)]
smod.append(0)

cmod = Counter(smod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = str(input())
N = len(S)
 
smod = [int(S[i:])%2019 for i in range(N)]
cmod = Counter(smod)
 
ans = 0
for x,y in cmod.items():
    if x == 0:
        y += 1
        ans += y*(y-1)/2
    else:
        ans += y*(y-1)/2
print(int(ans))

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = str(input())
N = len(S)

smod = [int(S[i:])%2019 for i in range(N)]
cmod = Counter(smod)

ans = 0
for x,y in cmod.items():
    if x == 0:
        y += 1
        ans += y*(y-1)/2
    else:
        ans += y*(y-1)/2
print(int(ans))

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
for i in range(N-3):
    for j in range(i+4,N):
        if j == i+4:
            temp = int(S[i:j+1])
        else:
            temp = temp*10 + int(S[j])
        #rint(temp)
        if temp%2019 == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
for i in range(N):
    for j in range(i+3,N):
        temp = int(S[i:j+1])
        if temp%2019 == 0:
            ans += 1

print(ans)
    

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)

ans = 0
for i in range(N):
    for j in range(i+3,N):
        temp = int(S[i:j+1])
        if temp%2019 == 0:
            ans += 1

print(ans)
    

Fixed submission:
from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))