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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * 10 ** (len(S) - 1 - i)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [T.count(i) for i in range(2019)]
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))

    # mx = int(S) // 2019
    # print(mx)
    # bl = [2019 * i for i in range(1, mx+1)]
    # ct = 0
    # for b in bl:
    #     blen = len(str(b))
    #     for i in range(len(S) - blen + 1):
    #         s = S[i:(i+blen)]
    #         if s == b:
    #             ct += 1
    # print(ct)

    # bf = [0 for _ in range(2019)]
    # for i in range(len(S)):



    # sl = [int(S[i]) for i in range(len(S))]
    # ct = 0
    # for i in range(len(S)):
    #     crt = sl[i]
    #     for j in range(i, len(S)):
    #         if i != j:
    #             crt *= 10
    #             crt += sl[j]
    #         # s = S[i:(j+1)]
    #         # si = int(s)
    #         if crt % 2019 == 0:
    #             ct += 1
    # print(ct)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    sl = [int(S[i]) for i in range(len(S))]
    ct = 0
    for i in range(len(S)):
        crt = sl[i]
        for j in range(i, len(S)):
            if i != j:
                crt *= 10
                crt += sl[j]
            # s = S[i:(j+1)]
            # si = int(s)
            if crt % 2019 == 0:
                ct += 1
    print(ct)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    ct = 0
    for i in range(len(S)):
        for j in range(i, len(S)):
            s = S[i:(j+1)]
            si = int(s)
            if si % 2019 == 0:
                ct += 1
    print(ct)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()