Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = (int(s[-(1+i)])*10**i) % 2019 
        r[i] = (temp+r[i-1])%2019
 
    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1
 
    print(ans)
main()

Fixed submission:
def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    temp = r[0]
    for i in range(1,len(s)):
        r[i] = (int(s[-(1+i)])*10**i+ temp) % 2019
        temp = r[i]
    
    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1

    print(ans)
main()

Fixed submission:
def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        r[i] = (int(s[-(1+i)])*10**i+ r[i-1]) % 2019
    
    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1
        
    print(ans)
main()

Fixed submission:
def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import collections as c
s = input()
r = [0]*len(s)
r[0] = int(s[-1])
for i in range(1,len(s)):
  r[i] = (int(s[-(1+i)])*10**i+ r[i-1]) % 2019

rc = c.Counter(r)
rl = list(rc.values())
sum = 0
for i in rl:
  sum += int(i*(i-1)/2)

if 0 in rc:
	sum+=1

print(sum)

Fixed submission:
def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import collections as c
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        r[i] = (int(s[-(1+i)])*10**i+ r[i-1]) % 2019
    
    rc = c.Counter(r)
    rl = list(rc.values())
    sum = 0
    for i in rl:
        sum += int(i*(i-1)/2)

    if 0 in rc:
        sum+=1

    print(sum)

main()

Fixed submission:
def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()