Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, input()))
n = len(S)
 
fl = [False]*(n+1)
res = 0
 
for i in range(n-3):
    if fl[i]:
        continue
    
    x = 0
    cnt = 0
    for j in range(i, n):
        x = (x*10+S[j])%2019
        
        if x == 0:
            cnt += 1
            fl[j+1] = True
            
    
    res += (cnt+1)*cnt//2
 
print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, input()))
n = len(S)
 
fl = [False]*(n+1)
res = 0
 
for i in range(n-3):
    if fl[i]:
        continue
    
    x = 0
    cnt = 0
    for j in range(i, n):
        x *= 10
        x += S[j]
        x %= 2019
        if x == 0:
            cnt += 1
            fl[j+1] = True
            
    
    res += (cnt+1)*cnt//2
 
print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, input()))
n = len(S)
 
fl = [False]*(n+1)
res = 0
 
for i in range(n-3):
    if fl[i]:
        continue
    
    x = 0
    cnt = 0
    for j in range(i, n):
        x *= 10
        x += S[j]
        x %= 2019
        if x == 0:
            cnt += 1
            fl[j+1] = True
            
    
    res += (cnt+1)*cnt//2
 
print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
intS = list(map(int, S))
n = len(S)

fl = [False]*(n+1)
l = 0
res = 0

for i in range(n-3):
    if fl[i]:
        continue
    
    x = int(S[i:i+3])
    l = 0
    cnt = 0
    for j in range(i+3, n):
        x *= 10
        x += intS[j]
        x %= 2019
        if x == 0:
            cnt += 1
            l = j+1
            fl[l] = True
            
    
    res += (cnt+1)*cnt//2

print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
intS = list(map(int, S))
n = len(S)

fl = [False]*n
l = 0
res = 0

for i in range(n-3):
    if fl[i]:
        continue
    
    x = int(S[i:i+3])
    l = 0
    cnt = 0
    for j in range(i+3, n):
        x *= 10
        x += intS[j]
        x %= 2019
        if x == 0:
            cnt += 1
            fl[l] = True
            l = j+1
    
    res += (cnt+1)*cnt//2

print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

fl = [False]*len(S)
l = 0
res = 0

for i in range(len(S)-3):
    if fl[i]:
        continue
    
    x = int(S[i:i+3])
    l = 0
    cnt = 0
    for j in range(i+3, len(S)):
        x *= 10
        x += int(S[j])
        x %= 2019
        if x == 0:
            cnt += 1
            fl[l] = True
            l = j+1
    
    res += (cnt+1)*cnt//2

print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Runtime Error):
S = input()

fl = [False]*len(S)
l = 0
res = 0

for i in range(len(S)-3):
    if fl[i]:
        continue
    
    x = int(S[i:i+3])
    cnt = 0
    for j in range(i+3, len(S)):
        x *= 10
        x += int(S[j])
        x %= 2019
        if x == 0:
            cnt += 1
            fl[l] = True
            l = j+1
    
    res += (cnt+1)*cnt//2

print(res)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

cnt = 0

for i in range(len(S)-3):
    x = int(S[i:i+3])
    for j in range(i+3, len(S)):
        x *= 10
        x += int(S[j])
        x %= 2019
        if x == 0:
            cnt += 1

print(cnt)

Fixed submission:
S = list(map(int, list(input())))
S.reverse()
a = [0]*len(S)
y = 2019
x = 1
t = 0
cnt = [0]*y
res = 0
for i in range(len(S)):
    cnt[t] += 1
    t += S[i]*x
    t %= y
    res += cnt[t]
    x = x*10%y
print(res)