Buggy python submission (verdict: Time Limit Exceeded):
#abc164-4
s = input()

counts = [0]*2019#modの値と個数を記録するリスト
d = 0
counts[0] += 1
for i in range(0,len(s)):
    d += int(s[-i-1])*(10**i)
    #print(d, d%2019)
    counts[d % 2019] += 1
#print(counts)
sumcount = 0
for m in counts:
    sumcount += m*(m-1)/2
print(int(sumcount))
#TLE

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):
#abc164-4
s = input()

counts = [0 for _ in range(2019)]#modの値と個数を記録するリスト
d = 0
counts[0] += 1
for i in range(0,len(s)):
    d += int(s[-i-1])*(10**i)
    #print(d, d%2019)
    counts[d % 2019] += 1
#print(counts)
sumcount = 0
for m in counts:
    sumcount += m*(m-1)/2
print(int(sumcount))
#TLE

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: Runtime Error):
#abc164-4
s = input()

counts = [0 for _ in range(2018)]#modの値と個数を記録するリスト
counts[0] += 1
d = 0
for i in range(0,len(s)):
    d += int(s[-i-1])*(10**i)
    #print(d)
    counts[d % 2019] += 1
#print(counts)
sumcount = 0

for m in counts:
    sumcount += m*(m-1)/2
print(int(sumcount))
#TLE

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: Runtime Error):
#abc164-4
import collections
s = input()

counts = [0 for _ in range(2018)]#modの値と個数を記録するリスト
counts[0] += 1
d = 0
for i in range(0,len(s)):
    d += int(s[-i-1])*(10**i)
    #print(d)
    counts[d % 2019] += 1
#print(counts)
sumcount = 0

for m in counts:
    sumcount += m*(m-1)/2
print(int(sumcount))
#TLE

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):
#abc164-4
import collections
s = input()

counts = []#modの値と個数を記録するリスト

for i in range(len(s)):
    counts.append(int(s[i:]) % 2019)
counts.append(0)
c = collections.Counter(counts)
mlist = list(c.values())
sumcount = 0
for m in mlist:
    sumcount += m*(m-1)/2
print(int(sumcount))
    

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):
Slist = list(input())
keta = len(Slist)
count = 0
for i in range(keta):
    for j in range(i+3,keta):
        a = Slist[i:j+1]
        if int("".join(a))%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) # 答えの出力