Buggy python submission (verdict: Time Limit Exceeded):
S = input()
a = len(S)
mod = 0
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(10**(a-1-i))+mod) %2019
    L[mod] += 1  
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)

Fixed submission:
S = input()
a = len(S)
mod = 0
ten = 1
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(ten)+mod) %2019
    L[mod] += 1
    ten = (ten*10)%2019
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
a = len(S)
L_1 = [0]
for i in range(a):
    L_1.append(int(S[:i+1])%3)
L_2 = [0]
for i in range(a):
    L_2.append(int(S[:i+1])%673)
k = 0
M = []
for j in range(a+1):
  M.append(10**j % 673)
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if L_1[y] == L_1[x-1]:
            if (L_2[x-1]*M[y-x+1] - L_2[y]) % 673 == 0:
                k += 1
print(k)

Fixed submission:
S = input()
a = len(S)
mod = 0
ten = 1
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(ten)+mod) %2019
    L[mod] += 1
    ten = (ten*10)%2019
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
a = len(S)
L = [0]
for i in range(a):
    L.append(int(S[:i+1])%2019)
k = 0
M = []
for j in range(a+1):
  M.append(10**j % 2019)
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if (L[x-1]*M[y-x+1] - L[y]) % 2019 == 0:
            k += 1
print(k)

Fixed submission:
S = input()
a = len(S)
mod = 0
ten = 1
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(ten)+mod) %2019
    L[mod] += 1
    ten = (ten*10)%2019
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
a = len(S)
L = [0]
for i in range(a):
    L.append(int(S[:i+1])%2019)
k = 0
M = []
for j in range(a+1):
  M.append(10**j % 2019)
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if (L[x-1]*M[y-x+1] - L[y]) % 2019 == 0:
            k += 1
print(k)

Fixed submission:
S = input()
a = len(S)
mod = 0
ten = 1
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(ten)+mod) %2019
    L[mod] += 1
    ten = (ten*10)%2019
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
a = len(S)
L = [0]
for i in range(a):
    L.append(int(S[:i+1])%2019)
k = 0
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if (L[x-1]*(10**(y-x+1)) - L[y]) % 2019 == 0:
            k += 1
print(k)

Fixed submission:
S = input()
a = len(S)
mod = 0
ten = 1
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(ten)+mod) %2019
    L[mod] += 1
    ten = (ten*10)%2019
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
a = len(S)
L = [0]
for i in range(a):
    L.append(int(S[:i+1])%2019)
k = 0
#x文字目からy文字目
for x in range(1,a+1):
    for y in range(x,a+1):
        if (L[x-1]*(10**(y-x+1)) - L[y]) % 2019 == 0:
            k += 1
print(k)

Fixed submission:
S = input()
a = len(S)
mod = 0
ten = 1
L = [0]*2019 #余りの列
L[0] = 1
for i in range(a-1,-1,-1):
    mod = (int(S[i])*(ten)+mod) %2019
    L[mod] += 1
    ten = (ten*10)%2019
ans = 0
for i in L:
  ans += i*(i-1)//2
print(ans)