Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 2019
DP = [0] * mod
DP[0] = 1
t = 1
value = 0
for i in reversed(S):
    value += int(i) * t
    res = value % mod
    DP[res] += 1
    t *= 10
print(int(sum([i * (i-1) / 2 for i in DP])))

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 2019
DP = [0] * mod
DP[0] = 1
t = 1
value = 0
for i in reversed(S):
    value += int(i) * t
    DP[value % mod] += 1
    t *= 10
print(int(sum([i * (i-1) / 2 for i in DP])))

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    S_list = []
    for i in range(len(S)):
        S_list.append(int(S[i]))
    num = 0
    for i in range(len(S_list)-3):
        sum_temp = 0
        k = 0
        for v in range(i, i+3)[::-1]:
            sum_temp += 10**k*S_list[v]
            k += 1
        for j in range(i+3, len(S)):
            #print(S_list[j])
            sum_temp *= 10
            sum_temp += S_list[j]
            if sum_temp % 2019 == 0:
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def main():
    S = input()
    S_list = []
    for i in range(len(S)):
        S_list.append(int(S[i]))
    S_list = np.array(S_list)
    num = 0
    for i in range(len(S_list)-3):
        sum_temp = np.sum([v * np.power(10, k) for k, v in enumerate(S_list[i:i+3][::-1])])
        #print(i, i+3, sum_temp)
        k = 0
        for j in range(i+3, len(S)):
            #print(S_list[j])
            sum_temp *= 10
            sum_temp += S_list[j]
            if sum_temp % 2019 == 0:
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Buggy python submission (verdict: Runtime Error):
import numpy as np
S = input()
S_list = []
for i in range(len(S)):
    S_list.append(int(S[i]))
S_list = np.array(S_list)
num = 0
for i in range(len(S_list)-3):
    sum_temp = np.sum([v * np.power(10, k) for k, v in enumerate(S_list[i:i+3][::-1])])
    #print(i, i+3, sum_temp)
    k = 0
    for j in range(i+3, len(S)):
        #print(S_list[j])
        sum_temp *= 10
        sum_temp += S_list[j]
        if sum_temp % 2019 == 0:
            num += 1
print(num)

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
S = input()
S_list = []
for i in range(len(S)):
    S_list.append(int(S[i]))
S_list = np.array(S_list)
num = 0
for i in range(len(S_list)-3):
    sum_temp = np.sum([v * np.power(10, k) for k, v in enumerate(S_list[i:i+3][::-1])])
    for j in range(i+3, len(S)):
        sum_temp *= 10
        sum_temp += S_list[j]
        if sum_temp % 2019 == 0:
            num += 1
print(num)

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
S = input()
S_list = []
for i in range(len(S)):
    S_list.append(int(S[i]))
S_list = np.array(S_list)
num = 0
for i in range(len(S_list)-3):
    #print(S_list[i], S_list[i+3])
    for j in range(i+3, len(S)):
        #print("\t", i, j, S_list[j], np.sum(S_list[i:j+1]))
        sum_temp = np.sum([v * np.power(10, k) for k, v in enumerate(S_list[i:j+1][::-1])])
        if sum_temp % 2019 == 0:
            num += 1
print(num)

Fixed submission:
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))