Buggy python submission (verdict: Time Limit Exceeded):
S = input()
leng = len(S)
S = S[::-1]

count = [0] * 2019
count[0] = 1

num = 0
d = 1

for char in S:
    num += int(char) * d
    num %= 2019
    count[num] += 1
    d *= 10


res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2

print(res)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

count = [0] * 2019
count[0] = 1

num = 0
d = 1

for i in range(leng):
    num += int(S[leng-1-i]) * d
    num %= 2019
    count[num] += 1
    d *= 10


res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2

print(res)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

count = [0] * 2019
count[0] = 1

num = 0
d = 1

for i in range(leng):
    num = int(S[i:])
    num %= 2019
    count[num] += 1
    d *= 10


res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
print(res)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = int(S[i:]) % 2019
    count[remainder] += 1

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
print(res)


Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = int(S[i:]) % 2019
    count[remainder] += 1

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
print(res)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

leng = len(str(S))
count = 0

for j in range(leng-3):
    for i in range(leng-j, 3, -1):
        partial = S // (10 ** j)
        partial = partial % (10 ** i)
        if partial == 0:
            continue
        if partial % 2019 == 0:
            count += 1
print(count)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

str_S = str(S)
count = 0

for i in range(len(str_S)-3):
    for j in range(i+4, len(str_S)+1):
        partial = int(str_S[i:j])
        if partial % 2019 == 0:
            count += 1

print(count)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

str_S = str(S)
count = 0

for i in range(len(str_S)-1):
    for j in range(i+1, len(str_S)+1):
        partial = int(str_S[i:j])
        if partial % 2019 == 0:
            count += 1

print(count)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

str_S = str(S)
count = 0

for i in range(len(str_S)-1):
    for j in range(i+1, len(str_S)+1):
        partial = int(str_S[i:j])
        if partial % 2019 == 0:
            count += 1

print(count)

Fixed submission:
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)