Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10

print(result)

Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  d *= 10

print(sum([i*(i-1)//2 for i in counter]))

Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  d *= 10

print(sum([i*(i-1)//2 for i in counter]))

Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = defaultdict(int)
counter[mods[-1]] += 1
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  d *= 10

print(sum([i*(i-1)//2 for i in counter.values()]))


Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = defaultdict(int)
counter[mods[-1]] += 1
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  d *= 10
  
result = 0
for j in counter.values():
  if j >= 2:
    result += j*(j-1)//2
print(result)

Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S = input()
S = S[::-1]
d = 1
mods = [0]
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  d *= 10
  
c = collections.Counter(mods)
result = 0
for i,j in c.most_common():
  if j >= 2:
    result += j*(j-1)//2
print(result)

Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S = input()
S = S[::-1]
d = 1
mods = [0]
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  d *= 10
  
c = collections.Counter(mods)
result = 0
for i,j in c.most_common():
  if j >= 2:
    result += j*(j-1)//2
print(result)

Fixed submission:
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)