Buggy python submission (verdict: Time Limit Exceeded):
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit*=10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Buggy python submission (verdict: Time Limit Exceeded):
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    mc[mt]+=1
    digit*=10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Buggy python submission (verdict: Time Limit Exceeded):
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    digit*=10%2019
    
print(cnt)

Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Buggy python submission (verdict: Time Limit Exceeded):
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    digit*=10
    
print(cnt)


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Buggy python submission (verdict: Time Limit Exceeded):
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

for i in range(L):
    mt=int(S[L-1-i:])%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    
print(cnt)


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Buggy python submission (verdict: Time Limit Exceeded):
cnt=0
S=str(input())
m=[0]*len(S)
L=len(S)

for i in range(L):
    m[i]=int(S[L-1-i:])%2019
    if m[i]==0:cnt+=1
    for j in range(L-i,L):
        if m[i]==m[L-1-j]:
            cnt+=1 
print(cnt)


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Buggy python submission (verdict: Time Limit Exceeded):
cnt=0
S=str(input())
m=[0]*len(S)
for i in range(len(S)):
    m[i]=int(S[i:])%2019 
    if m[i]==0:
        cnt+=1
for i in range(len(S)):
    for j in range(i+1,len(S)):
        if m[i]==m[j]:
            cnt+=1 
print(cnt)


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

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


Fixed submission:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit=digit*10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])