Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = int(input())
n = len(str(s))
d = 1
cnt = [0]*2019
for i in range(n+1):
    cnt[(s%d)%2019] += 1
    d *= 10


#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
cnt = [0]*2019
cnt[0] += 1
for i in range(n):
    cnt[int(s[i:])%2019] += 1

'''
slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)
cnt = [0]*2019

for m in slist:
    cnt[m] += 1
'''
ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
cnt = [0]*2019
cnt[0] += 1
for i in range(n):
    cnt[int(s[i:])%2019] += 1

'''
slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)
cnt = [0]*2019

for m in slist:
    cnt[m] += 1
'''
ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = int(input())
n = len(str(s))
slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)
cnt = [0]*2019

for m in slist:
    cnt[m] += 1

ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
cnts = [0]*2019
cnts[0] = 1
ans = 0
for i in range(n):
    cnts[int(s[i:])%2019] += 1

for cnt in cnts:
    if cnt >= 2:
        ans += cnt * (cnt-1) //2
print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
alist = [int(s[i:])%2019 for i in range(n)] + [0]
from collections import Counter
a_counter = Counter(alist)
a_counter = a_counter.most_common()
ans = 0

for i in range(len(a_counter)):
    if a_counter[i][1] >= 2:
        ans += a_counter[i][1]*(a_counter[i][1]-1)//2
print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

ans = 0
for i in range(n-3):
    for j in range(i+3,n):
        if int(s[i:j+1]) % 2019 == 0:
            ans += 1
            break
print(ans)



Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(n-3):
    for j in range(i+3,n):
        if int(s[i:j+1]) % 2019 == 0:
            ans += 1
print(ans)


Fixed submission:
s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


ans = 0
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)