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

Fixed submission:
from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=[int(x) for x in input()]
from collections import deque
L=deque()
sum=0
for i in range(len(s)):
    t=s[i]*(10**(len(s)-i))
    sum += t
    L.append(sum%2019)
L=sorted(L)

ans=0
count=1
for i in range(len(L)-1):
    if L[i]==L[i+1]:
        count += 1
    else:
        if L[i]==0:
            count += 1
        if count>1:
            ans += count*(count-1)//2
        count=1
if count>1:
    ans += count*(count-1)//2

print(ans)


Fixed submission:
from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=[int(x) for x in input()]
L=[]
sum=0
for i in range(len(s)):
    t=s[i]*(10**(len(s)-i))
    sum += t
    L.append(sum%2019)
L.sort()

ans=0
count=1
for i in range(len(L)-1):
    if L[i]==L[i+1]:
        count += 1
    else:
        if L[i]==0:
            count += 1
        if count>1:
            ans += count*(count-1)//2
        count=1
if count>1:
    ans += count*(count-1)//2

print(ans)


Fixed submission:
from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=[int(x) for x in input()]
L=[]
sum=0
for i in range(len(s)):
    t=s[i]*(10**(len(s)-i))
    sum += t
    L.append(sum%2019)
import collections
L=collections.Counter(L)
L=L.most_common()
ans=0
for i in L:
    if i[0]==0:
        ans += i[1]*(i[1]+1)//2
    elif i[1]>1:
        ans += i[1]*(i[1]-1)//2
print(ans)


Fixed submission:
from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=[str(x) for x in input()]

sum=0
for i in range(len(s)-4):
    for j in range(i+4,len(s)):
        t=''.join(s[i:j+1])
        if int(t)%2019==0:
            sum+=1
print(sum)

Fixed submission:
from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s=[str(x) for x in input()]

sum=0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        t=''.join(s[i:j+1])
        if int(t)%2019==0:
            sum+=1
print(sum)

Fixed submission:
from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)