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

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
for i in reversed(S):
    check_S += int(i) * (10 ** count)
    mod = check_S % 2019
    # mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)


Fixed submission:
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)

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

count = 0
mod_check = {}
mod_check[0] = 1
check_S = 0
for i in reversed(S):
    check_S += int(i) * (10 ** count)
    mod = check_S % 2019
    mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
    count += 1
mod_match = 0
for x in mod_check.values():
    mod_match += x * (x - 1) // 2
print(mod_match)


Fixed submission:
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)

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

count = 0
mod_check = {}
mod_check[0] = 1
check_S = 0
for i in reversed(S):
    check_S += int(i) * (10 ** count)
    mod = check_S % 2019
    mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
    count += 1
mod_match = 0
for x in mod_check.values():
    mod_match += x * (x - 1) // 2
print(mod_match)


Fixed submission:
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)

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

count = 0
mod_check = {}
mod_check[0] = 1
check_S = 0
for x in range(len(S) - 1, -1, -1):
    check_S += int(S[x]) * (10 ** (len(S) - x - 1))
    mod = check_S % 2019
    mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
mod_match = 0
for x in mod_check.values():
    mod_match += x * (x - 1) // 2
print(mod_match)


Fixed submission:
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)

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

count = 0
mod_check = {}
mod_check[0] = 1
for x in range(len(S) - 1, -1, -1):
    check_S = int(S[x:])
    mod = check_S % 2019
    mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
mod_match = 0
for x in mod_check.values():
    mod_match += x * (x - 1) // 2
print(mod_match)


Fixed submission:
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)

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

count = 0
for y in range(len(S) - 3):
    for x in range(len(S) - y - 3):
        check_S = int(S[y:x + y + 4])
        if check_S % 2019 == 0:
            count += 1
print(count)


Fixed submission:
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)