Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
num = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    num += int(S[i]) * d
    num %= 2019
    # num = (num + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[num] += 1
    d *= 10

ans = 0
for c in cnt:
    ans += c * (c-1) // 2
print(ans)

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 = list(input())
N = len(S)
num = 0
cnt = [0]*2019
cnt[0] = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    d = 10 ** (N-i-1)
    num += int(S[i]) * d
    num %= 2019
    # num = (num + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[num] += 1

ans = 0
for c in cnt:
    ans += c * (c-1) // 2
print(ans)

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 = list(input())
N = len(S)
num = 0
cnt = [0]*2019
cnt[0] = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    num += int(S[i]) * 10 ** (N-i-1)
    num %= 2019
    # num = (num + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[num] += 1

ans = 0
for c in cnt:
    ans += c * (c-1) // 2
print(ans)

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 = list(input())
N = len(S)
num = 0
cnt = [0]*2019
cnt[0] = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    num = (num + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[num] += 1

ans = 0
for c in cnt:
    ans += c * (c-1) // 2
print(ans)

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 = list(input())
N = len(S)
T = [0] * (N+1)
cnt = [0]*2019
cnt[0] = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    T[i] = (T[i+1] + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[T[i]] += 1

ans = 0
for c in cnt:
    ans += c * (c-1) // 2
print(ans)

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()
N = len(S)
T = [0] * (N+1)
cnt = {i:0 for i in range(2019)}
cnt[0] = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    T[i] = (T[i+1] + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[T[i]] += 1

ans = 0
for i in range(2019):
    m = cnt[i]
    ans += m * (m-1) // 2
print(ans)


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()
N = len(S)
T = [0] * (N+1)
cnt = {i:0 for i in range(2019)}
cnt[0] = 1
#T[i]: i+1文字目以降を数とみなしたときの数
for i in range(N-1, -1, -1):
    T[i] = (T[i+1] + int(S[i]) * 10 ** (N- i -1)) % 2019
    cnt[T[i]] += 1

ans = 0
for i in range(2019):
    m = cnt[i]
    ans += m * (m-1) // 2
print(ans)


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):
def main():
    s = input()
    N = len(s)

    l = []
    sum = 0

    for i in range(N):
        if i == N-1:
            l.append(0)
        l.append(int(s[i:N])%2019)
        
    lset = set(l)
    for key in lset:
        m = l.count(key)
        sum += m*(m-1)//2
    print(sum)

if __name__ == "__main__":
    main()

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):
from collections import Counter

s = input()
N = len(s)

l = []
sum = 0

for i in range(N):
    if i == N-1:
        l.append(0)
    l.append(int(s[i:N])%2019)
    
c = Counter(l)
for key in c.keys():
    m = c[key]
    sum += m*(m-1)/2
print(int(sum))

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()
N = len(s)

def f(c):
    for i in range(N):
        for j in range(i, N):
            if int(s[i:j+1])%2019 == 0:
                c += 1 
    print(c)
f(0)


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()
len = len(s)
count = 0
for i in range(len):
    for j in range(i, len):
        str = s[i:j+1]
        if int(str) % 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) # 答えの出力