Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int, list(input())))[::-1]
n = len(s)
c = [0]*2019
c[0]+=1
t = 0
ten = 1
for i in range(n):
    t = (t+s[i]*ten) % 2019
    ten*=10
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = list(map(int, list(input())))[::-1]
n = len(s)
c = Counter([])
c[0]+=1
t = 0
ten = 1
for i in range(n):
    t = (t+s[i]*ten) % 2019
    ten*=10
    c[t]+=1
ans = 0
for v in c.values():
    ans+=v*(v-1)//2
print(ans)


Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = list(map(int, list(input())))[::-1]
n = len(s)
c = Counter([])
c[0]+=1
t = 0
for i in range(n):
    t = (t+int(s[i])*pow(10, i))%2019
    c[t]+=1
ans = 0
for v in c.values():
    ans+=v*(v-1)//2
print(ans)

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
n = len(s)
c = Counter([])
c[0]+=1
for i in range(n):
    t = int(s[i:])%2019
    c[t]+=1
ans = 0
for v in c.values():
    ans+=v*(v-1)//2
print(ans)

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
n = len(s)

dp = [0] * (n+1)

for i in range(n):
    t = int(s[i:])%2019
    dp[i] = t
c = Counter(dp)
ans = 0
for k, v in c.items():
    ans+=v*(v-1)//2
print(ans)

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
n = len(s)

dp = [0] * (n+1)

for i in range(n):
    t = int(s[i:])%2019
    dp[i] = t
c = Counter(dp)
ans = 0
for k, v in c.items():
    ans+=v*(v-1)//2
print(ans)

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sl = list(map(int, list(s)))
n = len(s)
slc = [0] * (n+1)
for i in range(n):
    slc[i+1] += sl[i]+slc[i]
ans = 0
for i in range(n-4):
    for j in range(i+4, n+1):
        if (slc[j]-slc[i])%3 ==0 and int(s[i:j])%2019==0:
            ans+=1
print(ans)

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

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

Fixed submission:
s = input()

n = len(s)
c = [0]*2019
c[0]+=1
t = 0
digit = 1
for ss in s[::-1]:
    t = (t+int(ss)*digit) % 2019
    digit = (digit * 10) % 2019
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)