Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  for i, d in enumerate(map(int, list(s[::-1]))):
    x = d * (10**i) + remain
    remain = x % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  k = 1
  for d in map(int, list(s[::-1])):
    x = d * k + remain
    remain = x % 2019
    k = (10 * k) % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import (
  Counter, 
  defaultdict )

def main():
  s = input().strip()
  x = remain = 0
  remains = defaultdict(int)
  for i, d in enumerate(map(int, list(s[::-1]))):
    x = d * (10**i) + x
    remain = x % 2019
    remains[remain] += 1

  cnt = 0
  for k, v in remains.items():
    cnt += (v * (v - 1)) // 2
    if k == 0:
      cnt += v
  print(cnt)
  
if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  k = 1
  for d in map(int, list(s[::-1])):
    x = d * k + remain
    remain = x % 2019
    k = (10 * k) % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()

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

def main():
  s = input().strip()
  remains = Counter([int(s[-i:]) % 2019 for i in range(1, len(s)+1)]).items()

  cnt = 0
  for k, v in remains:
    cnt += (v * (v - 1)) // 2
    if k == 0:
      cnt += v
  print(cnt)
  
if __name__=='__main__':
  main()


Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  k = 1
  for d in map(int, list(s[::-1])):
    x = d * k + remain
    remain = x % 2019
    k = (10 * k) % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  s = input().strip()
  remains = dict(Counter([int(s[-i:]) % 2019 for i in range(1, len(s)+1)]).items())

  cnt = 0
  for k, v in remains.items():
    cnt += (v * (v - 1)) // 2
    if k == 0:
      cnt += v
  print(cnt)
  
if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  k = 1
  for d in map(int, list(s[::-1])):
    x = d * k + remain
    remain = x % 2019
    k = (10 * k) % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  s = input().strip()
  remains = dict(Counter([int(s[-i:]) % 2019 for i in range(1, len(s)+1)]).items())

  cnt = 0
  for k, v in remains.items():
    cnt += (v * (v - 1)) // 2
    if k == 0:
      cnt += v
  print(cnt)
  
if __name__=='__main__':
  main()



Fixed submission:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  k = 1
  for d in map(int, list(s[::-1])):
    x = d * k + remain
    remain = x % 2019
    k = (10 * k) % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()