Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
Smod = [0]*2019
for i in range(len(str(S))+1):
  Smod[(S%(10**i))%2019] += 1

ans = 0
for j in range(2019):
  ansj = Smod[j]
  ans += ansj * (ansj-1) // 2
print(ans)

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
Smod = [0]*2019
for i in range(len(str(S))+1):
  Smod[(S%(10**i))%2019] += 1

ans = 0
for j in range(2019):
  ans += Smod[j] * (Smod[j]-1) // 2
print(ans)

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

S = int(input())
Smod = [0]*2019
for i in range(int(math.log10(S)+2)):
  Smod[(S%(10**i))%2019] += 1

ans = 0
for j in range(2019):
  ans += Smod[j] * (Smod[j]-1) // 2
print(ans)

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

S = int(input())
Smod = [0]*2019
for i in range(int(math.log10(S)+2)):
  Smod[(S%(10**i))%2019] += 1

ans = 0
for j in range(2019):
  ans += Smod[j] * (Smod[j]-1) // 2
print(ans)

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S = input()
n = len(S)
x = 0
Timod_list = []

for i in range(n):
  Ti_list = S[i:n+1]
  Ti_str = ""
  for y in Ti_list:
    Ti_str = Ti_str + y
  Ti = int(Ti_str)
  Timod = Ti % 2019
  Timod_list = Timod_list + [Timod]

Timod_list.sort()
Timodlist_len= len(Timod_list)

Tlist0 = Timod_list.count(0)
x = x + Tlist0

Timod_lists = [x for x in Timod_list if Timod_list.count(x) > 1]
Timodlists_len = len(Timod_lists)

for j in range(Timodlists_len):
  Tlist = Timod_lists.count(Timod_lists[j])
  x = x + 1 / 2 * math.factorial(Tlist) / Tlist
    
x = int(x)
print(x) 

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S_list = list(input())
n = len(S_list)
x = 0
Timod_list = []

for i in range(n):
  Ti_list = S_list[i:n+1]
  Ti_str = ""
  for y in Ti_list:
    Ti_str = Ti_str + y
  Ti = int(Ti_str)
  Timod = Ti % 2019
  Timod_list = Timod_list + [Timod]

Timod_list.sort()
Timodlist_len= len(Timod_list)

Tlist0 = Timod_list.count(0)
x = x + Tlist0

Timod_lists = [x for x in Timod_list if Timod_list.count(x) > 1]
Timodlists_len = len(Timod_lists)

for j in range(Timodlists_len):
  Tlist = Timod_lists.count(Timod_lists[j])
  x = x + 1 / 2 * math.factorial(Tlist) / Tlist
    
x = int(x)
print(x) 

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S_list = list(input())
n = len(S_list)
x = 0
Timod_list = []

for i in range(n):
  Ti_list = S_list[i:n+1]
  Ti_str = ""
  for y in Ti_list:
    Ti_str = Ti_str + y
  Ti = int(Ti_str)
  Timod = Ti % 2019
  Timod_list = Timod_list + [Timod]

Timod_list.sort()
Timodlist_len= len(Timod_list)

Tlist0 = Timod_list.count(0)
x = x + Tlist0

for j in range(Timodlist_len-1):
  if Timod_list[j] == Timod_list[j + 1]:
    Tlist = Timod_list.count(Timod_list[j])
    x = x + 1 / 2 * math.factorial(Tlist) / (Tlist - 1)
    
x = int(x)
print(x) 

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S_list = list(input())
i = len(S_list)

x = 0

for n_0 in range(i-3):
  for n in range(n_0+4, i+1):
    Si_list = S_list[n_0 : n]
    Si_str = ""
    for y in Si_list:
      Si_str = Si_str + y
    Si = int(Si_str)
    if Si % 2019 == 0:
      x = x + 1
      
print(x)

Fixed submission:
S = input()
Sliststr = list(S)
Slist = [int(s) for s in Sliststr]
Smod = [0]
mod10 = [1]
count = [0]*2019
ans = 0
for i in range(len(S)-1):
  mod10.append(mod10[i]*10%2019)
for i in range(len(S)):
  Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019)
for i in range(len(Smod)):
  count[Smod[i]] += 1
for i in range(2019):
  ans += count[i] * (count[i]-1) // 2
print(ans)