Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
li = []
dic = {}
ans = 0

s = 0
for i in range(len(S)):
  s += int(S[len(S)-1-i]) * (10**i)
  s = s % 2019
  if s == 0:
    ans += 1
  elif s not in li:
    li.append(s)
  elif s not in dic:
    dic[s] = 2
  else:
    dic[s] += 1
  
li = list(dic.values())
for l in li:
  ans += l * (l-1) // 2

print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
li = []
dic = {}
ans = 0

for i in range(len(S)):
  s = int(S[i:]) % 2019
  if s == 0:
    ans += 1
  elif s not in li:
    li.append(s)
  elif s not in dic:
    dic[s] = 2
  else:
    dic[s] += 1
  
li = list(dic.values())
for l in li:
  ans += l * (l-1) // 2

print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
li = [0]*2019
ans = 0

for i in range(len(S)):
  s = int(S[i:]) % 2019
  if s == 0:
    ans += 1
  else:
    li[s] += 1
  
for l in li:
  if l > 1:
    ans += l*(l-1)//2

print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
l = len(S)
ans = 0
for i in range(l-3):
  for j in range(i+4, l+1):
    s = int(S[i:j])
    if s % 2019 == 0:
      ans += 1
print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
l = len(S)
ans = 0
for i in range(l-3):
  for j in range(i+4, l+1):
    s = int(S[i:j])
    if s % 2019 == 0:
      ans += 1
print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections
S = str(input())

l = []
for i,j in itertools.combinations(range(len(S)), 2):
  l.append((int(S[i:j+1]))%2019)
      
print(l.count(0))

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

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

ans = 0
for i,j in itertools.combinations(range(len(S)), 2):
  if int(S[i:j+1]) % 2019 == 0:
    ans += 1
      
print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

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

ans = [i+j for i,j in itertools.combinations(range(int(len(S))), 2) if int(S[i:j+1]) % 2019 == 0]
      
print(len(ans))

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

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

ans = [i+j for i,j in itertools.combinations(range(int(len(S))), 2) if int(S[i:j+1]) % 2019 == 0]
      
print(len(ans))

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

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

ans = 0
for i,j in itertools.combinations(range(int(len(S))), 2):
  if int(S[i:j+1]) % 2019 == 0:
    ans += 1
      
print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Buggy python submission (verdict: Runtime Error):
S = str(input())

ans = 0
for i,j in itertools.combinations_with_replacement(range(len(S)+1), 2):
  if int(S[i:j+1]) % 2019 == 0:
    ans += 1
      
print(ans)


Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

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

ans = 0
for i in range(len(S)):
  for j in range(i+3, len(S)):
    if int(S[i:j+1]) % 2019 == 0:
      ans += 1
      
print(ans)


Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

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

ans = 0
for i in range(len(S)):
  for j in range(i+3, len(S)):
    if int(S[i:j+1]) % 2019 == 0:
      ans += 1
      
print(ans)

Fixed submission:
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)