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

mods = []
cnt = 0
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    if mod == 0:
        cnt += 1
    else:
        cnt += mods.count(mod)
        mods.append(mod)

print(cnt)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

mods = []
cnt = 0
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    if mod == 0:
        cnt += 1
    else:
        cnt += mods.count(mod)
        mods.append(mod)

print(cnt)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

mods = []
cnt = 0
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    if mod == 0:
        cnt += 1
    else:
        mods.append(mod)

cnt += len(mods) - len(set(mods))
print(cnt)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

mods = []
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mods.append(mod)

import collections
c = collections.Counter(mods)
cnt = 0
for k, v in c.items():
    if k == 0:
        cnt += v
    if v > 1:
        cnt += v * (v-1) / 2
print(int(cnt))

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

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



Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

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

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

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

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



Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)