Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    S = input().strip()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    sums = [0]
    d = 1
    for c in S[::-1]:
        sums.append((sums[-1] + int(c) * d) % 2019)
        mod_count[sums[-1]] += 1
        d *= 10

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()

Fixed submission:
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
N = len(S)
SS = S[::-1]

mod_count = [0] * 2019
mod_count[0] = 1
sums = [0]
for i in range(N):
    sums.append((sums[-1] + int(SS[i]) * (10**i)) % 2019)
    mod_count[sums[-1]] += 1

print(sum([m * (m - 1) for m in mod_count]) // 2)


Fixed submission:
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
S = input().strip()
N = len(S)
SS = S[::-1]

mod_count = [0] * 2019
mod_count[0] = 1
sums = [0]
for i in range(N):
    sums.append((sums[-1] + int(SS[i]) * (10**i)) % 2019)
    mod_count[sums[-1]] += 1

print(sum([m * (m - 1) for m in mod_count]) // 2)

Fixed submission:
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
S = input().strip()
N = len(S)

mod_count = {0: 1}
SS = S[::-1]
sums = [0]
for i in range(N):
    sums.append((sums[-1] + int(SS[i]) * (10**i)) % 2019)
    mod_count[sums[-1]] = mod_count.get(sums[-1], 0) + 1

print(sum([m * (m - 1) for m in mod_count.values()]) // 2)

Fixed submission:
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
S = input().strip()
N = len(S)

mod_count = {0: 1}
for mod in [int(S[i:]) % 2019 for i in range(N)]:
    mod_count[mod] = mod_count.get(mod, 0) + 1

print(sum([m * (m - 1) for m in mod_count.values()]) // 2)

Fixed submission:
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
S = input().strip()
N = len(S)

# print([(i, j) for i in range(N) for j in range(i + 1, N + 1) if True or int(S[i:j]) % 2019 == 0])
print(sum([1 for i in range(N) for j in range(i + 1, N + 1) if int(S[i:j]) % 2019 == 0]))


Fixed submission:
#!/usr/bin/env python3


def main():
    S = input()
    N = len(S)

    mod_count = [0] * 2019
    mod_count[0] = 1
    ssum = 0
    for i, c in enumerate(S[::-1]):
        ssum = (ssum + int(c) * pow(10, i, 2019)) % 2019
        mod_count[ssum] += 1

    print(sum([m * (m - 1) for m in mod_count]) // 2)


if __name__ == "__main__":
    main()