Buggy python submission (verdict: Time Limit Exceeded):

S = input()[::-1]


def calculate(rs):
    # rs = reversed(s)

    sss = 0
    dict = [0] * 2019
    dict[0] = 1
    for index, c in enumerate(rs):
        sss = sss + int(c) * 10 ** index
        mod = sss % 2019
        dict[mod] = dict[mod] + 1

    res = 0
    for d in dict:
        if d > 1:
            res = res + d -1

    print(res)


calculate(S)


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


def calculate(s):
    rs = reversed(s)

    sss = 0
    dict = [0] * 2019
    dict[0] = 1
    for index, c in enumerate(rs):
        sss = sss + int(c) * 10 ** index
        mod = sss % 2019
        dict[mod] = dict[mod] + 1

    res = 0
    for d in dict:
        if d > 1:
            res = res + d -1

    print(res)


calculate(S)


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


def calculate(s):
    length = len(s)

    rs = reversed(s)

    sss = 0
    dict = {0: 1}
    for index, c in enumerate(rs):
        sss = sss + int(c) * 10 ** index
        mod = sss % 2019

        if dict.get(mod) == None:
            dict.__setitem__(mod, 1)
        else:
            dict.__setitem__(mod, dict.get(mod) + 1)


    res = 0
    for d in dict.values():
        if d > 1:
            res = res + d -1

    print(res)


calculate(S)


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

def comn(n,m):
    originamN = n
    s1 = 1
    s2 = 1
    while n >= (originamN-m + 1):
        s1 = s1 * n
        n = n - 1

    while m >= 1:
        s2 = s2 * m
        m = m - 1

    return s1 // s2


def calculate(s):
    length = len(s)

    dict = {0:1}
    for i in range(len(s)):
        index = (int(s[i:length]) % 2019)
        if dict.get(index) != None:
            dict.__setitem__(index, dict.get(index) + 1)
        else:
            dict.__setitem__(index, 1)

    result = 0
    for val in dict.values():
        if val > 1:
            result = result + val - 1

    print(result)
calculate(S)


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

def comn(n,m):
    originamN = n
    s1 = 1
    s2 = 1
    while n >= (originamN-m + 1):
        s1 = s1 * n
        n = n - 1

    while m >= 1:
        s2 = s2 * m
        m = m - 1

    return s1 // s2



def calculate(s):
    length = len(s)

    dict = {0:1}
    for i in range(len(s)):
        index = (int(s[i:length]) % 2019)
        if dict.get(index) != None:
            dict.__setitem__(index, dict.get(index) + 1)
        else:
            dict.__setitem__(index, 1)

    result = 0
    for val in dict.values():
        if val > 1:
            result = result + comn(val,2)

    print(result)
calculate(S)


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) # 答えの出力