Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
si=int(s)
mod=2019
t={}
t[si%mod]=1
for i in range(n):
    si-=int(s[i])*pow(10,n-1-i,mod)
    a=si%mod
    if a in t:
        t[a]+=1
    else:
        t[a]=1
ans=0
for v in t.values():
    ans+=(v*(v-1))//2
print(ans)


Fixed submission:
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
si=int(s)
mod=2019
from collections import defaultdict
t=defaultdict(lambda:0)
for i in range(n):
    t[int(s[i:])%mod]+=1
t[0]+=1
ans=0
for v in t.values():
    ans+=(v*(v-1))//2
print(ans)

Fixed submission:
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
si=int(s)
mod=2019
t=[si%mod]
for i in range(n):
    si-=int(s[i])*pow(10,n-1-i)
    t.append(si%mod)
from collections import Counter
d=Counter(t)
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Fixed submission:
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
t=[]
mod=2019
for i in range(n):
    t.append(int(s[i:])%mod)
t.append(0)
from collections import Counter
d=Counter(t)
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Fixed submission:
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
t=[]
mod=2019
for i in range(n):
    a=0
    for j in range(i,n):
        a+=pow(10,n-1-j)*int(s[j])
    t.append(a%mod)
t.append(0)
from collections import Counter
d=Counter(t)
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Fixed submission:
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

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


Fixed submission:
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)