Buggy python submission (verdict: Time Limit Exceeded):
ans=0
s=input()
if len(s)<4:
  print(0)
  exit()
N=len(s)
L=list()
for i in range(N):
  L.append(int(s[i:])%2019)
L.append(0)
print(len(L)-len(set(L)))

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
ans=0
s=input()
if len(s)<4:
  print(0)
  exit()
N=len(s)
L=list()
for i in range(3,N):
  L.append(int(s[:i+1]))
for i in range(N-3):
  for j in range(4,i+5):
    if (L[i]%pow(10,j))%2019==0:
      ans+=1
print(ans)

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

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

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

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

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a=0
S=input()
N=len(S)
for i in range(N-3):
  for j in range(i+3,N):
    if sum(list(map(int,S[i:j+1])))%3==0:
      if int(S[i:j+1])%673==0:
        a=a+1
print(a)

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

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

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

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

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
a=0
S=int(input())
for i in range(N-3):
  for j in range(i+3,N+1):
    A=int(float(S[i:j+1]))
    if A%2019==0:
      a=a+1
print(a)

Fixed submission:
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)