Buggy python submission (verdict: Time Limit Exceeded):
S=input()
src=[0]*2019
ans=0
pre=0
for s in range(len(S)):
  x=int(S[-(s+1)])*(10**s)
  a=(x+pre)%2019
  src[a]+=1
  pre+=x
  ans+=src[a]-1
print(ans+src[0])

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
src=[0]*2019
ans=0
pre=0
for s in range(len(S)):
  a=(int(S[-(s+1)])*(10**s)+pre)%2019
  src[a]+=1
  pre+=int(S[-(s+1)])*(10**s)
  ans+=src[a]-1
print(ans+src[0])

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
src={0:0}
ans=0
pre=0
for s in range(len(S)):
  a=(int(S[-(s+1)])*(10**s)+pre)%2019
  if a not in src.keys():
    src[a]=1
  else:
    ans+=src[a]
    src[a]+=1
  pre+=int(S[-(s+1)])*(10**s)
print(ans+src[0])

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
S=input()
src={}
ans=0
pre=0
for s in range(len(S)):
  a=(int(S[-(s+1)])*(10**s)+pre)%2019
  if a not in src.keys():
    src[a]=1
  else:
    ans+=src[a]
    src[a]+=1
  pre+=int(S[-(s+1)])*(10**s)
print(ans+src[0])

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

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

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()
src=[10**n*int(S[-(n+1)]) for n in range(len(S))]
sumS=[0]
for s in range(len(src)):
  sumS.append((sumS[s]+src[s])%2019)
ans=0
s=collections.Counter(sumS)
s[0]-=1
for n in s.values():
  ans+=n*(n-1)//2
print(ans+s[0])

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()
src=[10**n*int(S[-(n+1)]) for n in range(len(S))]
sumS=[0]
for s in range(len(src)):
  sumS.append((sumS[s]+src[s])%2019)
sumS=sumS[1:]
ans=0
s=collections.Counter(sumS)

for n in s.values():
  ans+=n*(n-1)//2
print(ans+s[0])

Fixed submission:
S=input()
N=len(S)

a=0
t=1
d=[0]*2019
d[0]=1
for i in range(N):
  a+=int(S[N-1-i])*t
  a%=2019
  t*=10
  t%=2019
  d[a]+=1

ans=0
for n in d:
  ans += n*(n-1)//2
print(ans)