Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mod_bucket[mod] += 1

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mod_bucket[mod] += 1

ans = 0
for mod in mod_bucket:
    ans += int(mod * (mod-1) / 2)
print(ans)


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    last_j = i
    for j in range(i+4, len(S)+1):
        if (j-last_j) < 4 or is_end[j]:
            continue
        if int(S[i:j]) % 2019 == 0:
            is_end[j] = True
            last_j = j
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    r = 0
    for j in range(i+1, len(S)+1):
        r = r * 10 + int(S[j-1])
        if is_end[j]:
            continue
        r %= 2019
        if r == 0:
            is_end[j] = True
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    for j in range(i+1, len(S)+1):
        if is_end[j]:
            continue
        if int(S[i:j]) % 2019 == 0:
            is_end[j] = True
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    for j in range(i+1, len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            is_end[j] = True
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
cnt = 0
for i in range(len(S)):
    for j in range(1, len(S)+1):
        if i >= j:
            continue
        if int(S[i:j]) % 2019 == 0:
            cnt += 1
print(cnt)


Fixed submission:
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] += 1

_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p *= 10
    p %= 2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))