Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    for i in range(N):
        d = 10 ** i % 2019
        t += (int(S[-1-i]) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    for i in range(N):
        t = (t + int(S.pop()) * 10 ** i) % 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()

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

def main():
    S = list(map(int,list(input())))
    t = [0] * (len(S) + 1)
    for i in range(len(S)):
        t[i+1] = (t[i] + S.pop() * 10 ** i) % 2019
    count_dict = collections.Counter(t)
    result = sum([b*(b-1)//2 for a, b in count_dict.items()])
    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()

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

def main():
    S = list(map(int,list(input())))
    result = 0
    t = [0] * (len(S) + 1)
    for i in range(len(S)):
        t[i+1] = (t[i] + S[-i-1] * 10 ** i) % 2019
    count_dict = collections.Counter(t)
    for a, b in count_dict.items():
        result += b*(b-1) // 2

    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()

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

def main():
    S = input()
    result = 0
    t = [0] * (len(S) + 1)
    for i in range(len(S)):
        t[i+1] = int(S[-i-1:]) % 2019
    count_dict = collections.Counter(t)
    for a, b in count_dict.items():
        result += b*(b-1) // 2

    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()

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

def main():
    S = input()
    result = 0
    t = [0]
    for i in range(len(S)):
        t.append((t[-1]+int(S[-i-1])*10**i) % 2019)
    count_dict = collections.Counter(t)
    for a, b in count_dict.items():
        result += b*(b-1) // 2

    print(result)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    N = len(S)
    t = 0
    A = [0] * 2019
    A[0] += 1
    d = 1
    for s in reversed(S):
        d *= 10
        d %= 2019
        t += (int(s) * d)
        t %= 2019
        A[t] += 1
    result = sum([a*(a-1)//2 for a in A])
    print(result)


if __name__ == '__main__':
    main()