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

ans = 0
mods = []
x = int(s)%2019
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)%2019
    a = x%2019
    mods.append(a)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

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

ans = 0
mods = []
x = int(s)
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)
    a = x%2019
    mods.append(a)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

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

ans = 0
mods = {}
x = int(s)
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)
    a = x%2019
    if a in mods.keys():
        mods[a] += 1
    else:
        mods[a] = 1

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

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

ans = 0
mods = {0: 1} # 0 % n = 0
x = int(s)
for i in range(len(s)):
    if i != 0:
        x -= int(s[i-1]) * 10**(len(s)-i)
    a = x%2019
    if a in mods.keys():
        mods[a] += 1
    else:
        mods[a] = 1

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

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

ans = 0
mods = {0: 1} # 0 % n = 0
for i in range(1, len(s)+1):
    x = int(s[len(s)-i:])
    # print(x)
    a = x%2019
    if a in mods.keys():
        mods[a] += 1
    else:
        mods[a] = 1
# print(mods)
for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

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

ans = 0
for l in range(len(s)):
    for r in range(l+1, len(s)):
        # print("idx", l, r)
        s_l0 = s[l:]
        s_r10 = s[r+1:]
        if len(s_r10) != 0:
            x_l0 = int(s_l0)
            x_r10 = int(s_r10)
            if (x_l0 % 2019) == (x_r10 % 2019):
                ans += 1
                # print("l, r ({},{})".format(l+1, r+1))
        else:
            x_l0 = int(s_l0)
            if x_l0 % 2019 == 0:
                ans += 1
                # print("l, r ({},{})".format(l+1, r+1))
print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)

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

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

print(ans)

Fixed submission:
from collections import Counter
s = input()

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts * (counts-1) // 2
print(ans)