Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#n,p = map(int,input().split())
s=input()
p = 2019
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
for i in s[::-1]:
    i = int(i)
    tmp=(tmp+i*ten)%p
    ten = ten*10
    l[tmp]+=1
for i in l:
    ans+= i*(i-1)//2
print(ans)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#n,p = map(int,input().split())
s=input()
p = 2019
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
for i in s[::-1]:
    i = int(i)
    tmp=(tmp+i*ten)%p
    ten = ten*10
    l[tmp]+=1
for i in l:
    ans+= i*(i-1)//2
print(ans)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#n,p = map(int,input().split())
s=input()[::-1]
p = 2019
n = len(s)
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
for i in s:
    i = int(i)
    tmp=(tmp+i*ten)%p
    ten = ten*10
    l[tmp]+=1
for i in l:
    ans+= i*(i-1)//2
print(ans)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
p = 2019
n = len(s)
u_i = []
ans = 0
l = [0 for i in range(p)]
l[0] = 1
for i in range(n):
    l[int(s[i:])%p] += 1

for i in l:
    ans+= i*(i-1)//2
print(ans)

Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#n,p = map(int,input().split())
s = input()
p = 2019
n = len(s)
u_i = []
ans = 0
l = [0 for i in range(p)]
l[0] = 1
for i in range(n):
    l[int(s[i:])%p] += 1

for i in l:
    ans+= i*(i-1)//2
print(ans)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#n,p = map(int,input().split())
s = input()
p = 2019
n = len(s)
u_i = []
ans = 0
amari = [0]*p
amari[0] += 1
for i in range(n):
    amari[int(s[i:])%p] += 1

for i in amari:
    ans+= i*(i-1)//2
print(ans)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
#n,p = map(int,input().split())
s = input()
p = 2019
n = len(s)
u_i = []
ans = 0
for i in range(n):
    u_i.append(int(s[i:])%p)
u_i.append(0)
amari = [0]*p
for i in u_i:
    amari[i] += 1
for i in amari:
    ans+= i*(i-1)//2
print(ans)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
cnt = 0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        if int(s[i:j+1])%2019 == 0:
            cnt+=1
print(cnt)


Fixed submission:
p = 2019
s = input()
n = len(s)
l = [0 for i in range(p)]
l[0] = 1
ten = 1
cnt = 0
 
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    for i in range(n):
        cnt = (cnt + int(s[-i-1]) * ten) % p
        l[cnt] += 1
        ten = (ten * 10) % p
    for i in l:
        if i > 1:
            ans += i * (i - 1) // 2
print(ans)