Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    p *= 10
    m = d % n
    mod_list[m] += 1

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

for i in range(s_len):
    t_i = int(s[i:])
    m = t_i % n
    mod_list[m] += 1

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

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

s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

for i in range(s_len):
    t = s[i:]
    t_i = int(t)
    m = t_i % n
    #mod_list.append(m)
    mod_list[m] += 1

#c = collections.Counter(mod_list)
#result = sum(i * (i - 1) // 2 for i in c.values())
result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

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

s = input()
s_len = len(s)
n = 2019
mod_list = [0]

for i in range(s_len):
    t = s[i:]
    t_i = int(t)
    m = t_i % n
    mod_list.append(m)

c = collections.Counter(mod_list)
result = sum(i * (i - 1) // 2 for i in c.values())
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0
a = 202


@lru_cache(maxsize=128)
def reduce_number(s):
    left = int(s[:-1])
    right = a * int(s[-1])
    result = str(left + right)
    return result


@lru_cache(maxsize=128)
def is_multiple(s):
    _s = s
    while True:
        _s = reduce_number(_s)
        _s_int = int(_s)
        if _s_int == n:
            return True
        elif _s_int < n:
            return False


for i in range(s_len - n_len):
    for j in range(i + n_len, s_len + 1):
        m = s[i:j]
        if is_multiple(m):
            result += 1
            break
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0
a = 202


@lru_cache(maxsize=128)
def reduce_number(s):
    left = int(s[:-1])
    right = a * int(s[-1])
    result = str(left + right)
    return result


@lru_cache(maxsize=128)
def is_multiple(s):
    _s = s
    while True:
        _s = reduce_number(_s)
        _s_int = int(_s)
        if _s_int == n:
            return True
        elif _s_int < n:
            return False


for i in range(s_len - n_len):
    for j in range(i + n_len, s_len + 1):
        m = s[i:j]
        if is_multiple(m):
            result += 1
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0


@lru_cache(maxsize=128)
def is_multiple(x):
    return x % n == 0


for i in range(s_len - n_len):
    for j in range(i + n_len, s_len + 1):
        m = int(s[i:j])
        if is_multiple(m):
            result += 1
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0
for i in range(s_len - n_len):
    for j in range(i + n_len, s_len + 1):
        m = int(s[i:j])
        if m % n == 0:
            result += 1
print(result)

Fixed submission:
s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    m = d % n
    mod_list[m] += 1
    p *= 10
    p %= 2019

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)