Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = list(input())
    s = s[::-1]

    l = [[] for i in range(673)]
    l[0].append(0)
    ten = 1
    mod = 673
    now = 0
    for i in range(len(s)):
        now = (now+int(s[i])*ten)%mod
        l[now].append(i+1)
        ten *= 10
        ten %= mod
    ans = 0
    for i in l:
        if len(i) >= 2:
            for j in range(len(i)-1):
                for k in range(j+1,len(i)):
                    a = sum(list(map(int,s[i[j]:i[k]])))
                    if a %3 == 0:
                        ans += 1
    print(ans)
if __name__ == "__main__":
    main()


Fixed submission:
def main():
    s = list(input())
    s = s[::-1]

    l = [[[] for j in range(3)] for i in range(673)]
    l[0][0].append(0)
    mo = 0
    ten = 1
    mod = 673
    now = 0
    ans = 0
    for i in range(len(s)):
        a = int(s[i])*ten
        mo = (mo+a)%3
        now = (now+a)%mod
        if l[now][mo]:
            ans += len(l[now][mo])
        l[now][mo].append(i+1)
        ten *= 10
        ten %= 2019
    print(ans)
    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = list(input())
    s = s[::-1]

    l = [[[] for j in range(3)] for i in range(673)]
    l[0][0].append(0)
    mo = 0
    ten = 1
    mod = 673
    now = 0
    ans = 0
    for i in range(len(s)):
        a = int(s[i])*ten
        mo = (mo+a)%3
        now = (now+a)%mod
        if l[now][mo]:
            ans += len(l[now][mo])
        l[now][mo].append(i+1)
        ten *= 10
    print(ans)
    
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    s = list(input())
    s = s[::-1]

    l = [[[] for j in range(3)] for i in range(673)]
    l[0][0].append(0)
    mo = 0
    ten = 1
    mod = 673
    now = 0
    ans = 0
    for i in range(len(s)):
        a = int(s[i])*ten
        mo = (mo+a)%3
        now = (now+a)%mod
        if l[now][mo]:
            ans += len(l[now][mo])
        l[now][mo].append(i+1)
        ten *= 10
        ten %= 2019
    print(ans)
    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = list(input())
    s = s[::-1]

    l = [[] for i in range(673)]
    l[0].append(0)
    ten = 1
    mod = 673
    now = 0
    for i in range(len(s)):
        now = (now+int(s[i])*ten)%mod
        l[now].append(i+1)
        ten *= 10
    ans = 0
    for i in l:
        if len(i) >= 2:
            for j in range(len(i)-1):
                for k in range(j+1,len(i)):
                    a = sum(list(map(int,s[i[j]:i[k]])))
                    if a %3 == 0:
                        ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    s = list(input())
    s = s[::-1]

    l = [[[] for j in range(3)] for i in range(673)]
    l[0][0].append(0)
    mo = 0
    ten = 1
    mod = 673
    now = 0
    ans = 0
    for i in range(len(s)):
        a = int(s[i])*ten
        mo = (mo+a)%3
        now = (now+a)%mod
        if l[now][mo]:
            ans += len(l[now][mo])
        l[now][mo].append(i+1)
        ten *= 10
        ten %= 2019
    print(ans)
    
if __name__ == "__main__":
    main()