Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(lambda x: int(x),list(input())))
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
for i in range(n):
    kar = (kar + s[n-1-i]*10**i)%2019
    p[kar] += 1

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

Fixed submission:
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(lambda x: int(x),list(input())))
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
for i in range(n):
    kar = kar + s[n-1-i]*10**i
    p[kar%2019] += 1

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

Fixed submission:
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(lambda x: int(x),list(input())))
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
for i in range(n):
    kar = kar + s[n-1-i]*10**i
    p[kar%2019] += 1

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

Fixed submission:
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
import collections
s = list(input())
p = []
n = len(s)
kar = 0
for i in range(n):
    kar = (kar + int(s[n-1-i])*(10**i))%2019
    p.append(kar)
c = collections.Counter(p)
ans = 0
for x , y in c.items():
    ans += y*(y-1)//2
    if x == 0:
        ans += y
print(ans)

Fixed submission:
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
import collections
s = input()
p = []
for i in range(len(s)):
    p.append(int(s[i:])%2019)

c = collections.Counter(p)
ans = 0
for x , y in c.items():
    ans += y*(y-1)//2
    if x == 0:
        ans += y
print(ans)

Fixed submission:
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = len(s)
ans = 0
if n <= 3:
    print(0)
    exit()
elif n == 4:
    if int(s[0]*1000+s[1]*100+s[2]*10+s[3]) % 2019 == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
elif n > 4:
    for i in range(n-3):
        kar = int(s[i])*100 + int(s[i+1])*10 + int(s[i+2])
        for j in range(i+3,n):
            kar = (kar*10 + int(s[j])) %2019
            if kar == 0:
                ans += 1
print(ans)

Fixed submission:
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

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