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


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
for i in range(len(s)):
    lst_mod[int(s[i:]) % 2019] += 1
for mod in lst_mod:
    ans += comb(mod)
print(int(ans))


Fixed submission:
import collections


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
num, dim = 0, 1
for char in reversed(s):
    num += int(char)*dim
    num %= 2019
    dim *= 10
    dim %= 2019  # サイズを大きくしたくないからmod(2019)を使う
    lst_mod[num] += 1

for mod in lst_mod:
    ans += comb(mod)
print(int(ans))

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


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = []  # O(N)で回した連続値のmod(2019)の値
for i in range(len(s)):
    mod = int(s[i:]) % 2019
    lst_mod.append(mod)
    if mod == 0:
        ans = + 1

count = list(collections.Counter(lst_mod).values())
for i in range(len(count)):
    if count[i] == 1:
        continue
    ans += comb(count[i])
print(int(ans))


Fixed submission:
import collections


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
num, dim = 0, 1
for char in reversed(s):
    num += int(char)*dim
    num %= 2019
    dim *= 10
    dim %= 2019  # サイズを大きくしたくないからmod(2019)を使う
    lst_mod[num] += 1

for mod in lst_mod:
    ans += comb(mod)
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# # TLEだった
# s = input()
# counter = 0
# for i in range(3, len(s)+1):
#     snum = 0
#     for m in range(i):
#         snum += int(s[m])
#     num = int(s[0:i])
#     if num % 2019 == 0:
#         counter += 1
#     for j in range(1, len(s)-i+1):
#         snum -= int(s[j-1])
#         snum += int(s[j+i-1])
#         if snum % 3 != 0:
#             continue
#         num = int(s[j:j + i])
#         if num % 673 == 0:
#             counter += 1
# print(counter)

import collections


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = []  # O(N)で回した連続値のmod(2019)の値
for i in range(len(s)):
    mod = int(s[i:]) % 2019
    lst_mod.append(mod)
    if mod == 0:
        ans = + 1

count = list(collections.Counter(lst_mod).values())
for i in range(len(count)):
    ans += comb(count[i])
print(int(ans))


Fixed submission:
import collections


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
num, dim = 0, 1
for char in reversed(s):
    num += int(char)*dim
    num %= 2019
    dim *= 10
    dim %= 2019  # サイズを大きくしたくないからmod(2019)を使う
    lst_mod[num] += 1

for mod in lst_mod:
    ans += comb(mod)
print(int(ans))

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


Fixed submission:
import collections


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
num, dim = 0, 1
for char in reversed(s):
    num += int(char)*dim
    num %= 2019
    dim *= 10
    dim %= 2019  # サイズを大きくしたくないからmod(2019)を使う
    lst_mod[num] += 1

for mod in lst_mod:
    ans += comb(mod)
print(int(ans))

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


Fixed submission:
import collections


def comb(n):
    return n * (n-1)/2


s = input()
ans = 0
lst_mod = [0]*2019  # O(N)で回した連続値のmod(2019)の値
lst_mod[0] += 1
num, dim = 0, 1
for char in reversed(s):
    num += int(char)*dim
    num %= 2019
    dim *= 10
    dim %= 2019  # サイズを大きくしたくないからmod(2019)を使う
    lst_mod[num] += 1

for mod in lst_mod:
    ans += comb(mod)
print(int(ans))