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

ans = 0
cnt = [0] * 2019
s=""

for i in range(N)[::-1]:
    s = "".join([S[i],s])
    cnt[int(s) % 2019] += 1

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


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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

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

ans = 0
cnt = [0] * 2019
s=""

for i in range(N)[::-1]:
    s = S[i] + s
    cnt[int(s) % 2019] += 1

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


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
t = int(S)

ans = 0
cnt = [0] * 2019
for i in range(1, N+1):
    cnt[(t % (10)**i) % 2019] += 1
ans += cnt[0]
for i in range(1, 2019):
    if cnt[i] >= 2:
        ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
t = int(S)

ans = 0
cnt = [0] * 2019
for i in range(1, N+1):
    cnt[(t % (10)**i) % 2019] += 1
ans += cnt[0]
for i in range(1, 2019):
    if cnt[i] >= 2:
        ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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

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

ans = 0
cnt = [0] * 2019
for i in range(N):
    cnt[int(S[i:]) % 2019] += 1
ans+=cnt[0]
for i in range(1, 2019):
    if cnt[i]>=2:   
        ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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

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

ans = 0
num = []
cnt = [0] * 2019
for i in range(N):
    num.append(int(S[i:]))
    cnt[num[i] % 2019] += 1
for i in range(N):
    ans += cnt[i] * (cnt[i] + 1) // 2

print(ans)


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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

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

ans=0
for i in range(N-3):
    for j in range(i+4, N+1):
        if int(S[i:j])%2019 == 0:
            ans+=1
print(ans)


Fixed submission:
S = list(input())
N = len(S)

ans = 0
cnt = [0] * 2019
a = 1
s = 0

for i in range(N)[::-1]:
    s = int(S[i]) * a + s
    a *= 10
    a = a % 2019
    cnt[s % 2019] += 1
    s = s % 2019

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