Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ls_rem = []
for i in range(len(S)):
  p=int(S[i:len(S)])%2019
  ls_rem.append(p)
ls_rem.append(0)
from collections import Counter
C_rem = Counter(ls_rem)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)/2
print(int(ans))  

Fixed submission:
S = input()[::-1]

#aのMOD求めるンゴ
MOD=2019
ls_rem_a=[]
d=1
for i in range(len(S)):
  ls_rem_a.append(int(S[i])*d%MOD)
  d = d*10%MOD

#次に累積和求めるンゴ
ls_rem_s=[0]
sum=0
for i in range(len(S)):
  sum+=ls_rem_a[i]
  sum%=MOD
  ls_rem_s.append(sum)

#最後にMODが同じやつの個数を調べるンゴ
from collections import Counter
C_rem = Counter(ls_rem_s)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)//2
print(ans)

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

Fixed submission:
S = input()[::-1]

#aのMOD求めるンゴ
MOD=2019
ls_rem_a=[]
d=1
for i in range(len(S)):
  ls_rem_a.append(int(S[i])*d%MOD)
  d = d*10%MOD

#次に累積和求めるンゴ
ls_rem_s=[0]
sum=0
for i in range(len(S)):
  sum+=ls_rem_a[i]
  sum%=MOD
  ls_rem_s.append(sum)

#最後にMODが同じやつの個数を調べるンゴ
from collections import Counter
C_rem = Counter(ls_rem_s)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
List=list(N)
M=len(List)
ans=0
Mods=[0]*(M+1)
Sum=""
for i in range(M):
  Sum=List[M-i-1]+Sum
  Mods[M-i-1]=int(Sum)%2019
Mods.sort()

import collections
C=collections.Counter(Mods)
for j in range((Mods[M])):
  k=C[j]
  ans+=k*(k-1)/2
print(int(ans))

Fixed submission:
S = input()[::-1]

#aのMOD求めるンゴ
MOD=2019
ls_rem_a=[]
d=1
for i in range(len(S)):
  ls_rem_a.append(int(S[i])*d%MOD)
  d = d*10%MOD

#次に累積和求めるンゴ
ls_rem_s=[0]
sum=0
for i in range(len(S)):
  sum+=ls_rem_a[i]
  sum%=MOD
  ls_rem_s.append(sum)

#最後にMODが同じやつの個数を調べるンゴ
from collections import Counter
C_rem = Counter(ls_rem_s)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
List=list(N)
M=len(List)
ans=0
Mods=[0]*(M+1)
Mods[M]=0
Sum=""
for i in range(M):
  Sum=List[M-i-1]+Sum
  Mods[M-i-1]=int(Sum)%2019
Mods.sort()

import collections
C=collections.Counter(Mods)
for j in range((Mods[M])):
  if C[j]!=1:
    k=C[j]
    ans+=k*(k-1)/2
print(int(ans))

Fixed submission:
S = input()[::-1]

#aのMOD求めるンゴ
MOD=2019
ls_rem_a=[]
d=1
for i in range(len(S)):
  ls_rem_a.append(int(S[i])*d%MOD)
  d = d*10%MOD

#次に累積和求めるンゴ
ls_rem_s=[0]
sum=0
for i in range(len(S)):
  sum+=ls_rem_a[i]
  sum%=MOD
  ls_rem_s.append(sum)

#最後にMODが同じやつの個数を調べるンゴ
from collections import Counter
C_rem = Counter(ls_rem_s)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
List=list(N)
M=len(List)
ans=0
Mods=[0]*(M+1)
Mods[M]=0
Sum=""
for i in range(M):
  Sum=List[M-i-1]+Sum
  Mods[M-i-1]=int(Sum)%2019
Mods.sort()

import collections
C=collections.Counter(Mods)
for j in range((Mods[M])):
  if C[j]!=1:
    k=C[j]
    ans+=k*(k-1)/2
print(int(ans))

Fixed submission:
S = input()[::-1]

#aのMOD求めるンゴ
MOD=2019
ls_rem_a=[]
d=1
for i in range(len(S)):
  ls_rem_a.append(int(S[i])*d%MOD)
  d = d*10%MOD

#次に累積和求めるンゴ
ls_rem_s=[0]
sum=0
for i in range(len(S)):
  sum+=ls_rem_a[i]
  sum%=MOD
  ls_rem_s.append(sum)

#最後にMODが同じやつの個数を調べるンゴ
from collections import Counter
C_rem = Counter(ls_rem_s)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
List=list(N)
p=""
ans=0
for j in range(4,len(List)+1):
  for i in range(len(List)-j+1):
    for x in range(i,i+j):
      p += List[x]
    if int(p)%2019==0:
      ans+=1
    p=""
print(ans)

Fixed submission:
S = input()[::-1]

#aのMOD求めるンゴ
MOD=2019
ls_rem_a=[]
d=1
for i in range(len(S)):
  ls_rem_a.append(int(S[i])*d%MOD)
  d = d*10%MOD

#次に累積和求めるンゴ
ls_rem_s=[0]
sum=0
for i in range(len(S)):
  sum+=ls_rem_a[i]
  sum%=MOD
  ls_rem_s.append(sum)

#最後にMODが同じやつの個数を調べるンゴ
from collections import Counter
C_rem = Counter(ls_rem_s)
ans=0
for i in C_rem.keys():
  n=C_rem[i]
  ans+=n*(n-1)//2
print(ans)