Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
from tqdm import tqdm



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

@lru_cache()
def pow(i):
    if i==0:
        return 1
    elif i==1:
        return 10

    if i%2==0:
        return pow(i//2)*pow(i//2)
    else:
        return pow(i-1)*10

S=input()
count=[0 for i in range(2019)]
length=len(S)
S=int(S)

for i in range(length+1):
    n=S%pow(i)
    count[n%2019]+=1



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
count=[0 for i in range(2019)]
_S=S[::-1]
_S=_S+'0'
base=1
S=0
for i,s in enumerate(_S):
    S+=base*int(s)
    mod=(S%base)%2019
    count[mod]+=1
    base*=10



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
length=len(S)
S=int(S)
count=[0 for i in range(2019)]

base=1
for i in range(length+1):
    mod=(S%base)%2019
    count[mod]+=1
    base*=10


retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2

print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
length=len(S)
S=int(S)
count=[0 for i in range(2019)]

for i in range(length+1):
    mod=(S%(10**i))%2019
    count[mod]+=1


retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2

print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
length=len(S)
S=int(S)
count={}

for i in range(length+1):
    mod=(S%(10**i))%2019
    count[mod]=count.get(mod,0)+1


retval=0
for key in count:
    retval+=count[key]*(count[key]-1)//2

print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
S=S+'0'
length=len(S)

count={}

for i in range(length):
    count[int(S[i:])%2019]=count.get(int(S[i:])%2019,0)+1

retval=0
for key in count:
    retval+=count[key]*(count[key]-1)//2

print(retval)


Fixed submission:
from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)