Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    
    l = []
    base = 1
    for st in S[::-1]:
        l.append((int(st)*base)%2019)
        base *= 10
        
    cum = [0]
    
    for num in l:
        cum.append((cum[-1]+num)%2019)
    
    
    c = Counter(cum)
    
    ans = 0
    for it,num in c.items():
        ans += (num*(num-1))//2
    
    print(ans)    
    
    
    
    
    
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    S = input()
    
    base = 1
    cum = 0
    d = defaultdict(int)
    d[0] = 1
    ans = 0
    
    for st in S[::-1]:
        num = (int(st)*base)%2019
        base *= 10
        cum += num
        ans += d[cum%2019]
        d[cum%2019] += 1

    print(ans)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    S = input()
    
    base = 1
    cum = 0
    d = defaultdict(int)
    d[0] = 1
    ans = 0
    
    for st in S[::-1]:
        num = (int(st)*base)%2019
        base *= 10
        cum += num
        ans += d[cum%2019]
        d[cum%2019] += 1

    print(ans)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    S = input()
    
    l = []
    base = 1
    for st in S[::-1]:
        l.append((int(st)*base)%2019)
        base *= 10
        
    cum = 0
    d = defaultdict(int)
    d[0] = 1
    
    ans = 0
    for num in l:
        cum += num
        ans += d[cum%2019]
        d[cum%2019] += 1

    print(ans)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    S = input()
    
    l = []
    base = 1
    for st in S[::-1]:
        l.append((int(st)*base)%2019)
        base *= 10
        
    cum = 0
    d = defaultdict(int)
    d[0] = 1
    
    for num in l:
        cum += num
        d[cum%2019] += 1

    ans = 0
    for num in d.values():
        ans += (num*(num-1))//2
    
    print(ans)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    
    l = []
    base = 1
    for st in S[::-1]:
        l.append((int(st)*base)%2019)
        base *= 10
        
    cum = [0]
    
    for num in l:
        cum.append((cum[-1]+num)%2019)
    
    
    c = Counter(cum)
    
    ans = 0
    for it,num in c.items():
        ans += (num*(num-1))//2
    
    print(ans)    
    
    
    
    
    
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()