Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
a = [0] * 2019
a[0] = 1
for i in range(0, n):
  a[(int(s[i : n + 1]) % 2019)] += 1
ans = 0
for i in a:
  ans +=  i * (i - 1) // 2
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
a = [0] * 2019
a[0] = 1
for i in range(0, n):
  a[(int(s[i : n + 1]) % 2019)] += 1
ans = 0
for i in a:
  ans +=  i * (i - 1) // 2
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(len(s) - 4):
  for j in range(i + 4, len(s) + 1):
    if int(s[i : j]) % 2019 == 0:
      ans += 1
      break
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(len(s) - 4):
  for j in range(i + 4, len(s) + 1):
    if int(s[i : j]) % 2019 == 0:
      ans += 1
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = 0
for i in range(len(s) - 3):
  for j in range(i + 3, len(s) + 1):
    if int(s[i : i + 2]) % 2 == 1: break
    if int(s[i : j]) % 2019 == 0:
      ans += 1
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
for i in range(len(s) - 3):
  for j in range(i + 3, len(s) + 1):
    if int(s[i : j]) % 2019 == 0:
      ans += 1
print(ans)

Fixed submission:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  digit %= 2019
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)