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

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    # for i in range(n):
    #     #print(S[i:])
    #     T[i] = int(S[i:]) % 2019
    # print(T)
    for i in reversed(range(n)):
        T[i] = (int(S[i])*10**(n-1 -i) + T[i+1]) % 2019

    #print(T)
    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import collections

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    # for i in range(n):
    #     #print(S[i:])
    #     T[i] = int(S[i:]) % 2019
    # print(T)
    b = [1 for i in range(n)]
    for i in reversed(range(n-1)):
        b[i] = b[i+1]*10 % 2019
    #print(b)

    # for i in reversed(range(n)):
    #     T[i] = (int(S[i])*10**(n-1 -i) + T[i+1]) % 2019
    # print(T)

    for i in reversed(range(n)):
        T[i] = (b[i]*int(S[i]) + T[i+1]) % 2019
    #print(T)


    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()

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

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    for i in range(n):
        #print(S[i:])
        T[i] = int(S[i:]) % 2019
    #print(T)
    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import collections

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    # for i in range(n):
    #     #print(S[i:])
    #     T[i] = int(S[i:]) % 2019
    # print(T)
    b = [1 for i in range(n)]
    for i in reversed(range(n-1)):
        b[i] = b[i+1]*10 % 2019
    #print(b)

    # for i in reversed(range(n)):
    #     T[i] = (int(S[i])*10**(n-1 -i) + T[i+1]) % 2019
    # print(T)

    for i in reversed(range(n)):
        T[i] = (b[i]*int(S[i]) + T[i+1]) % 2019
    #print(T)


    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def solve(S, i, Ns):
    #print("i:{}".format(i))
    #print("Ns:{}".format(Ns)) 
    if len(S) <= i:
        return 0 # Ns[i] でインデックスの外
    if Ns[i] != -1:
        return Ns[i]
    N = 0
    for j in range(i+4, len(S)+1):
        s = int(S[i:j])
        #print(s)
        if s % 2019 == 0:
            N = 1+solve(S,i+j, Ns)
            break
    Ns[i] = N
    return N


if __name__ == "__main__":
    # 2019 = 3 * 673
    S = str(input())
    n = len(S)
    Ns = [-1 for i in range(n)]

    # ans = 0
    # # for i in range(2019):
    # #     for j in range(1, 10):
    # #         if (i*10+j) % 2019 == 0:
    # #             print(i,j)
    # # for i in range(0, n):
    # #     for j in range(i+1, n+1):
    # #         s = int(S[i:j])
    # #         #print(s)
    # #         if s % 2019 == 0:
    # #             #print("i,j : {}, {}".format(i, j))
    # #             ans += 1
    # print(ans)

    for i in range(len(S)):
        solve(S, i, Ns)
    #print(Ns)
    print(sum(Ns))




Fixed submission:
import numpy as np
import collections

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    # for i in range(n):
    #     #print(S[i:])
    #     T[i] = int(S[i:]) % 2019
    # print(T)
    b = [1 for i in range(n)]
    for i in reversed(range(n-1)):
        b[i] = b[i+1]*10 % 2019
    #print(b)

    # for i in reversed(range(n)):
    #     T[i] = (int(S[i])*10**(n-1 -i) + T[i+1]) % 2019
    # print(T)

    for i in reversed(range(n)):
        T[i] = (b[i]*int(S[i]) + T[i+1]) % 2019
    #print(T)


    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def solve(S, i, Ns):
    #print("i:{}".format(i))
    #print("Ns:{}".format(Ns)) 
    if len(S) <= i:
        return 0 # Ns[i] でインデックスの外
    if Ns[i] != -1:
        return Ns[i]
    N = 0
    for j in range(i+1, len(S)+1):
        s = int(S[i:j])
        if s % 2019 == 0:
            N = 1+solve(S,i+j, Ns)
            break
    Ns[i] = N
    return N


if __name__ == "__main__":
    # 2019 = 3 * 673
    S = str(input())
    n = len(S)
    Ns = [-1 for i in range(n)]

    # ans = 0
    # # for i in range(2019):
    # #     for j in range(1, 10):
    # #         if (i*10+j) % 2019 == 0:
    # #             print(i,j)
    # # for i in range(0, n):
    # #     for j in range(i+1, n+1):
    # #         s = int(S[i:j])
    # #         #print(s)
    # #         if s % 2019 == 0:
    # #             #print("i,j : {}, {}".format(i, j))
    # #             ans += 1
    # print(ans)

    for i in range(len(S)):
        solve(S, i, Ns)
    #print(Ns)
    print(sum(Ns))




Fixed submission:
import numpy as np
import collections

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    # for i in range(n):
    #     #print(S[i:])
    #     T[i] = int(S[i:]) % 2019
    # print(T)
    b = [1 for i in range(n)]
    for i in reversed(range(n-1)):
        b[i] = b[i+1]*10 % 2019
    #print(b)

    # for i in reversed(range(n)):
    #     T[i] = (int(S[i])*10**(n-1 -i) + T[i+1]) % 2019
    # print(T)

    for i in reversed(range(n)):
        T[i] = (b[i]*int(S[i]) + T[i+1]) % 2019
    #print(T)


    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()