Buggy python submission (verdict: Time Limit Exceeded):
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
ls = [0for i in range(2019)]

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    count += ls[x%2019]
    ls[x%2019] += 1
    pow10 *= 10

# for x in ls:
#     count += x*(x-1)/2

print(int(count))



Fixed submission:
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
# ls = [0for i in range(2019)]
ls = [0] * 2019

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    x %= 2019
    count += ls[x]
    ls[x] += 1
    pow10 *= 10
    pow10 %= 2019

# for x in ls:
#     count += x*(x-1)/2

print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]

# i~nまでの値をmod2019したときの数
ls = [0for i in range(2019)]

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in range(len(S)):
    x += int(S[i])*pow10
    count += ls[x%2019]
    ls[x%2019] += 1
    pow10 *= 10

# for x in ls:
#     count += x*(x-1)/2

print(int(count))



Fixed submission:
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
# ls = [0for i in range(2019)]
ls = [0] * 2019

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    x %= 2019
    count += ls[x]
    ls[x] += 1
    pow10 *= 10
    pow10 %= 2019

# for x in ls:
#     count += x*(x-1)/2

print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = S[::-1]

# i~nまでの値をmod2019したときの数
ls = [0for i in range(2019)]

# 0文字の時
ls[0] += 1

x = 0
for i in range(len(S)):
    x += int(S[i])*10**i
    ls[x%2019] += 1

count = 0
for x in ls:
    count += x*(x-1)/2

print(int(count))



Fixed submission:
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
# ls = [0for i in range(2019)]
ls = [0] * 2019

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    x %= 2019
    count += ls[x]
    ls[x] += 1
    pow10 *= 10
    pow10 %= 2019

# for x in ls:
#     count += x*(x-1)/2

print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

# i~nまでの値をmod2019したときの数
ls = [0for i in range(2019)]

# 0文字の時
ls[0] += 1

for i in range(len(S)):
    x = int(S[i:])%2019
    ls[x] += 1

count = 0
for i in range(2019):
    x = ls[i]
    count += x*(x-1)/2

print(int(count))



Fixed submission:
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
# ls = [0for i in range(2019)]
ls = [0] * 2019

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    x %= 2019
    count += ls[x]
    ls[x] += 1
    pow10 *= 10
    pow10 %= 2019

# for x in ls:
#     count += x*(x-1)/2

print(int(count))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

count = 0
for i in range(len(S)-4):
    for j in range(i+4, len(S)):
        x = int(S[i:j+1])
        if x % 2019 == 0:
            count += 1

print(count)

Fixed submission:
S = input()
digits = list(map(int,S))
# S = S[::-1]→これが時間かかる

# i~nまでの値をmod2019したときの数
# ls = [0for i in range(2019)]
ls = [0] * 2019

# 0文字の時
ls[0] += 1

x = 0
pow10 = 1
count = 0
for i in reversed(digits):
    x += i*pow10
    x %= 2019
    count += ls[x]
    ls[x] += 1
    pow10 *= 10
    pow10 %= 2019

# for x in ls:
#     count += x*(x-1)/2

print(int(count))