Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(1,n+1):
    ans += msum[:i].count(msum[i])
print(ans)

Fixed submission:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * n
cnt = [0] * (MOD)
t = 0
for i in range(n):
    m[i] = int(s[i]) * 10**i % MOD
    t =  (t + m[i]) % MOD
    msum[i] = copy.deepcopy(t)
    cnt[t] += 1

ans = copy.deepcopy(cnt[0])
for i in range(1,MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Fixed submission:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * n
cnt = [0] * (MOD)
t = 0
for i in range(n):
    m[i] = int(s[i]) * 10**i % MOD
    t =  (t + m[i]) % MOD
    msum[i] = copy.deepcopy(t)
    cnt[t] += 1

ans = copy.deepcopy(cnt[0])
for i in range(1,MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Fixed submission:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
t = 0
for i in range(n):
    m[i] = int(s[i]) * 10**i % MOD
    t =  (t + m[i]) % MOD
    msum[i+1] = copy.deepcopy(t)

cnt = 0
for i in range(1,n+1):
    cnt += msum[:i].count(msum[i])
print(cnt)

Fixed submission:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

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

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n

t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    t = t * 10 % MOD

cnt = 0
for cr in range(n):
    cm = 0
    for cl in range(cr, n):
        cm = (cm + m[cl]) % MOD
        if cm == 0:
            cnt += 1
print(cnt)


Fixed submission:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

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

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n

t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    t = t * 10 % MOD

cnt = 0
for cr in range(n):
    cm = 0
    for cl in range(cr, n):
        cm = (cm + m[cl]) % MOD
        if cm == 0:
            cnt += 1
print(cnt)

Fixed submission:
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)