Buggy python submission (verdict: Runtime Error):
def retry(list_S, ans, start_ii=0):
    if start_ii > len(list_S) - 3:
        return ans

    for start_i in range(start_ii, len(list_S) - 3):
        for last_i in range(start_i + 3, len(list_S)):
            tmp = ''.join(list_S[start_i:last_i + 1])

            if (int(tmp) % 2019) == 0:
                ans += 1
                return retry(list_S, ans, last_i)

    return ans


def resolve():
    S = input()
    list_S = list(S)
    ans = 0

    print(retry(list_S, ans))


resolve()

Fixed submission:
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()

Buggy python submission (verdict: Runtime Error):
def retry(list_S, ans, start_ii=0):
    if start_ii > len(list_S) - 3:
        return ans

    for start_i in range(start_ii, len(list_S) - 3):
        for last_i in range(start_i + 3, len(list_S)):
            tmp = ''.join(list_S[start_i:last_i + 1])

            if (int(tmp) % 2019) == 0:
                ans += 1
                retry(list_S, ans, last_i)

    return ans


def resolve():
    S = input()
    list_S = list(S)
    ans = 0

    print(retry(list_S, ans))


resolve()

Fixed submission:
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()

Buggy python submission (verdict: Runtime Error):
def retry(list_S, ans, start_ii=0):
    for start_i in range(start_ii, len(list_S) - 3):
        for last_i in range(start_i + 3, len(list_S)):
            tmp = ''.join(list_S[start_i:last_i + 1])

            if (int(tmp) % 2019) == 0:
                ans += 1
                retry(list_S, ans, last_i)

    return ans


def resolve():
    S = input()
    list_S = list(S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    ans = retry(list_S, ans)

    print(ans)


resolve()

Fixed submission:
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    S = input()
    list_S = list(S)
    len_S = len(list_S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    for start_i in range(0, len_S - 3):
        for last_i in range(start_i, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])
            if tmp:
                tmp_ans = int(tmp) % 2019

                if tmp_ans == 0:
                    ans += 1
    print(ans)


resolve()

Fixed submission:
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    S = input()
    list_S = list(S)
    len_S = len(list_S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    for start_i in range(0, len_S - 3):
        for last_i in range(3, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])
            if tmp:
                tmp_ans = int(tmp) % 2019

                if tmp_ans == 0:
                    ans += 1

    print(ans)


resolve()

Fixed submission:
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()