Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = list(map(int, S))

r = 0
pow10 = 1
counter = [0] * 2019
counter[0] = 1
for i in range(1, len(S) + 1):
    r = (r + pow10 * S[-i]) % 2019
    counter[r] += 1
    pow10 *= 10

ans = 0
for count in counter:
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = list(map(int, S))

nums = [0] * (len(S) + 1)
pow10 = 1
counter = dict({0: 1})
for i in range(1, len(S) + 1):
    nums[i] = (nums[i - 1] + pow10 * S[-i]) % 2019
    if nums[i] not in counter:
        counter[nums[i]] = 1
    else:
        counter[nums[i]] += 1

    pow10 *= 10

ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

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

S = input()
S = list(map(int, S))

nums = [0] * (len(S) + 1)
pow10 = 1
for i in range(1, len(S) + 1):
    nums[i] = (nums[i - 1] + pow10 * S[-i]) % 2019
    pow10 *= 10

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

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

S = input()
S = list(map(int, S))

S = S[::-1]
pow10 = 10
for i in range(1, len(S)):
    S[i] = S[i - 1] + S[i] * pow10
    pow10 *= 10

S = [0] + [n % 2019 for n in S]

counter = Counter(S)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

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

S = input()
S = list(map(int, S))

nums = S[::-1]
pow10 = 10
for i in range(1, len(nums)):
    nums[i] = nums[i - 1] + nums[i] * pow10
    pow10 *= 10

nums = [0] + [n % 2019 for n in nums]

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

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

S = input()
S = list(map(int, S))

nums = S[::-1]
for i in range(1, len(nums)):
    nums[i] = nums[i - 1] + nums[i] * 10 ** i

nums = [0] + [n % 2019 for n in nums]

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += factorial(count) // (factorial(count - 2) * factorial(2))

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

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

S = input()
S = list(map(int, S))

nums = S[::-1]
for i in range(1, len(nums)):
    nums[i] = nums[i - 1] + nums[i] * 10 ** i

nums = [0] + [n % 2019 for n in nums]

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += factorial(count) // (factorial(count - 2) * factorial(2))

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

ans = 0
for i in range(len(S)):
    for j in range(i + 4, len(S) + 1):
        n = int(S[i:j])
        ans += n % 2019 == 0

print(ans)


Fixed submission:
S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)