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

target = 2019

# s = reversed(original)

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

digit = 1
mod = 0
for c in original:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    counts[mod] += 1
    # count = countOfMod.get(mod, 0) + 1
    # countOfMod[mod] = count
    # if countOfMod[mod] > 1:
    #     results.setdefault(mod, int(count*(count-1)/2))

# print(sum(results.values()))

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

print(ans)  # 答えの出力

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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):
original = input()[::-1]

target = 2019

# s = reversed(original)
s = original

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

digit = 1
mod = 0
for c in s:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    counts[mod] += 1
    # count = countOfMod.get(mod, 0) + 1
    # countOfMod[mod] = count
    # if countOfMod[mod] > 1:
    #     results.setdefault(mod, int(count*(count-1)/2))

# print(sum(results.values()))

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

print(ans)  # 答えの出力

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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):
original = input()

target = 2019

results = {}
countOfMod = {0:1}
s = reversed(original)

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

digit = 1
mod = 0
for c in s:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    counts[mod] += 1
    # count = countOfMod.get(mod, 0) + 1
    # countOfMod[mod] = count
    # if countOfMod[mod] > 1:
    #     results.setdefault(mod, int(count*(count-1)/2))

# print(sum(results.values()))

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

print(ans)  # 答えの出力

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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):
original = input()

target = 2019

results = {}
countOfMod = {}
length = len(str(original))
for i in range(0, length+1):
    value = int(original[-i:]) if i > 0 else 0
    mod = value % target
    val = countOfMod.get(mod, 0) + 1
    countOfMod[mod] = val
    if countOfMod[mod] > 1:
        results.setdefault(mod, int(val*(val-1)/2))

print(sum(results.values()))


Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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()

target = 2019

memo = [0]*200000

counts = []
countOfMod = {}
# i = 0
# while s >= 10:
#     mod = s % target
#     s = int(s / 10)
#     countOfMod[mod] = countOfMod.get(mod, 0) + 1

length = len(s)
for i in range(0, length+1):
    value = int(s[-i:]) if i > 0 else 0
    mod = value % target
    countOfMod[mod] = countOfMod.get(mod, 0) + 1

results = [int(m*(m-1)/2) for m in countOfMod.values() if m > 1]


print(sum(results))
# print(count)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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()

length = len(s)

target = 2019


dic = {}
for i in range(0, length+1):
    value = int(s[-i:]) if i > 0 else 0
    mod = value % target
    dic[mod] = dic.get(mod, []) + [i]

counts = [len(vals) for vals in dic.values() if len(vals) > 1]

# count = 0
# for m in counts:
#     count += int(m(m-1)/2)

results = [int(m*(m-1)/2) for m in counts]

print(sum(results))
# print(count)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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()
# s = '14282668646'

length = len(s)

count = 0
for i in range(length):
    for j in range(i+4, length+1):
        if(int(s[i:j]) % 2019 == 0):
            count += 1
print(count)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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()
# s = '14282668646'

length = len(s)

count = 0
for i in range(length):
    for j in range(i+4, length+1):
        if(int(s[i:j]) % 2019 == 0):
            count += 1
print(count)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

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)